|
1 | 1 | import { StackFrame } from '@sentry/types';
|
2 | 2 |
|
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'; |
4 | 10 |
|
5 | 11 | describe('getEventDescription()', () => {
|
6 | 12 | test('message event', () => {
|
@@ -220,3 +226,32 @@ describe('stripQueryStringAndFragment', () => {
|
220 | 226 | expect(stripUrlQueryAndFragment(urlWithQueryStringAndFragment)).toBe(urlString);
|
221 | 227 | });
|
222 | 228 | });
|
| 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