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