Skip to content

Commit 99024b2

Browse files
committed
add tests for checkOrSetAlreadyCaught
1 parent 654f62a commit 99024b2

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

packages/utils/test/misc.test.ts

+36-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { StackFrame } from '@sentry/types';
22

3-
import { addContextToFrame, getEventDescription, parseRetryAfterHeader, stripUrlQueryAndFragment } from '../src/misc';
3+
import {
4+
addContextToFrame,
5+
checkOrSetAlreadyCaught,
6+
getEventDescription,
7+
parseRetryAfterHeader,
8+
stripUrlQueryAndFragment,
9+
} from '../src/misc';
410

511
describe('getEventDescription()', () => {
612
test('message event', () => {
@@ -220,3 +226,32 @@ describe('stripQueryStringAndFragment', () => {
220226
expect(stripUrlQueryAndFragment(urlWithQueryStringAndFragment)).toBe(urlString);
221227
});
222228
});
229+
230+
describe('checkOrSetAlreadyCaught()', () => {
231+
describe('ignores primitives', () => {
232+
it.each([
233+
['undefined', undefined],
234+
['null', null],
235+
['number', 1231],
236+
['boolean', true],
237+
['string', 'Dogs are great!'],
238+
])('%s', (_case: string, exception: unknown): void => {
239+
// in this case, "ignore" just means reporting them as unseen without actually doing anything to them (which of
240+
// course it can't anyway, because primitives are immutable)
241+
expect(checkOrSetAlreadyCaught(exception)).toBe(false);
242+
});
243+
});
244+
245+
it("recognizes exceptions it's seen before", () => {
246+
const exception = { message: 'Oh, no! Charlie ate the flip-flops! :-(', __sentry_captured__: true };
247+
248+
expect(checkOrSetAlreadyCaught(exception)).toBe(true);
249+
});
250+
251+
it('recognizes new exceptions as new and marks them as seen', () => {
252+
const exception = { message: 'Oh, no! Charlie ate the flip-flops! :-(' };
253+
254+
expect(checkOrSetAlreadyCaught(exception)).toBe(false);
255+
expect((exception as any).__sentry_captured__).toBe(true);
256+
});
257+
});

0 commit comments

Comments
 (0)