Skip to content

Commit 753b719

Browse files
authored
chore(core): Add test for addExceptionMechanism (#4073)
Extracted from #4068, to ensure that it doesn't break current behavior.
1 parent 111ea28 commit 753b719

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

packages/utils/test/misc.test.ts

+33-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
import { StackFrame } from '@sentry/types';
1+
import { Event, Mechanism, StackFrame } from '@sentry/types';
22

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

511
describe('getEventDescription()', () => {
612
test('message event', () => {
@@ -220,3 +226,28 @@ describe('stripQueryStringAndFragment', () => {
220226
expect(stripUrlQueryAndFragment(urlWithQueryStringAndFragment)).toBe(urlString);
221227
});
222228
});
229+
230+
describe('addExceptionMechanism', () => {
231+
type EventWithException = Event & {
232+
exception: {
233+
values: [{ type?: string; value?: string; mechanism?: Mechanism }];
234+
};
235+
};
236+
237+
const baseEvent: EventWithException = {
238+
exception: { values: [{ type: 'Error', value: 'Oh, no! Charlie ate the flip-flops! :-(' }] },
239+
};
240+
241+
it('adds data to event, preferring incoming values to current values', () => {
242+
const event = { ...baseEvent };
243+
244+
const currentMechanism = { type: 'instrument', handled: false };
245+
const newMechanism = { handled: true, synthetic: true };
246+
event.exception.values[0].mechanism = currentMechanism;
247+
248+
addExceptionMechanism(event, newMechanism);
249+
250+
// the new `handled` value took precedence
251+
expect(event.exception.values[0].mechanism).toEqual({ type: 'instrument', handled: true, synthetic: true });
252+
});
253+
});

0 commit comments

Comments
 (0)