Skip to content

Commit 3636ee7

Browse files
committed
add tests for checkOrSetAlreadyCaught
1 parent 800675e commit 3636ee7

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

packages/utils/test/misc.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Event, Mechanism, StackFrame } from '@sentry/types';
33
import {
44
addContextToFrame,
55
addExceptionMechanism,
6+
checkOrSetAlreadyCaught,
67
getEventDescription,
78
parseRetryAfterHeader,
89
stripUrlQueryAndFragment,
@@ -288,3 +289,32 @@ describe('addExceptionMechanism', () => {
288289
});
289290
});
290291
});
292+
293+
describe('checkOrSetAlreadyCaught()', () => {
294+
describe('ignores primitives', () => {
295+
it.each([
296+
['undefined', undefined],
297+
['null', null],
298+
['number', 1231],
299+
['boolean', true],
300+
['string', 'Dogs are great!'],
301+
])('%s', (_case: string, exception: unknown): void => {
302+
// in this case, "ignore" just means reporting them as unseen without actually doing anything to them (which of
303+
// course it can't anyway, because primitives are immutable)
304+
expect(checkOrSetAlreadyCaught(exception)).toBe(false);
305+
});
306+
});
307+
308+
it("recognizes exceptions it's seen before", () => {
309+
const exception = { message: 'Oh, no! Charlie ate the flip-flops! :-(', __sentry_captured__: true };
310+
311+
expect(checkOrSetAlreadyCaught(exception)).toBe(true);
312+
});
313+
314+
it('recognizes new exceptions as new and marks them as seen', () => {
315+
const exception = { message: 'Oh, no! Charlie ate the flip-flops! :-(' };
316+
317+
expect(checkOrSetAlreadyCaught(exception)).toBe(false);
318+
expect((exception as any).__sentry_captured__).toBe(true);
319+
});
320+
});

0 commit comments

Comments
 (0)