diff --git a/packages/utils/test/misc.test.ts b/packages/utils/test/misc.test.ts index 3faf4f955067..c4b18e107997 100644 --- a/packages/utils/test/misc.test.ts +++ b/packages/utils/test/misc.test.ts @@ -1,6 +1,12 @@ -import { StackFrame } from '@sentry/types'; +import { Event, Mechanism, StackFrame } from '@sentry/types'; -import { addContextToFrame, getEventDescription, parseRetryAfterHeader, stripUrlQueryAndFragment } from '../src/misc'; +import { + addContextToFrame, + addExceptionMechanism, + getEventDescription, + parseRetryAfterHeader, + stripUrlQueryAndFragment, +} from '../src/misc'; describe('getEventDescription()', () => { test('message event', () => { @@ -220,3 +226,28 @@ describe('stripQueryStringAndFragment', () => { expect(stripUrlQueryAndFragment(urlWithQueryStringAndFragment)).toBe(urlString); }); }); + +describe('addExceptionMechanism', () => { + type EventWithException = Event & { + exception: { + values: [{ type?: string; value?: string; mechanism?: Mechanism }]; + }; + }; + + const baseEvent: EventWithException = { + exception: { values: [{ type: 'Error', value: 'Oh, no! Charlie ate the flip-flops! :-(' }] }, + }; + + it('adds data to event, preferring incoming values to current values', () => { + const event = { ...baseEvent }; + + const currentMechanism = { type: 'instrument', handled: false }; + const newMechanism = { handled: true, synthetic: true }; + event.exception.values[0].mechanism = currentMechanism; + + addExceptionMechanism(event, newMechanism); + + // the new `handled` value took precedence + expect(event.exception.values[0].mechanism).toEqual({ type: 'instrument', handled: true, synthetic: true }); + }); +});