Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions packages/utils/test/misc.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -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 });
});
});