|
1 | 1 | jest.mock('../../src/js/integrations/reactnativeerrorhandlersutils');
|
2 | 2 |
|
3 |
| -import type { ExtendedError, SeverityLevel } from '@sentry/core'; |
| 3 | +import type { ExtendedError, Mechanism, SeverityLevel } from '@sentry/core'; |
4 | 4 | import { setCurrentClient } from '@sentry/core';
|
5 | 5 |
|
6 | 6 | import { reactNativeErrorHandlersIntegration } from '../../src/js/integrations/reactnativeerrorhandlers';
|
@@ -123,5 +123,28 @@ describe('ReactNativeErrorHandlers', () => {
|
123 | 123 | expect(mockEnable).toHaveBeenCalledTimes(1);
|
124 | 124 | expect(actualSyntheticError).toBeUndefined();
|
125 | 125 | });
|
| 126 | + |
| 127 | + test('unhandled rejected sets error mechanism', async () => { |
| 128 | + const integration = reactNativeErrorHandlersIntegration(); |
| 129 | + integration.setupOnce(); |
| 130 | + |
| 131 | + const [actualTrackingOptions] = mockEnable.mock.calls[0] || []; |
| 132 | + actualTrackingOptions?.onUnhandled?.(1, 'Test Error'); |
| 133 | + |
| 134 | + await client.flush(); |
| 135 | + const actualSyntheticError = client.hint?.syntheticException; |
| 136 | + const errorMechanism = client.event?.exception?.values[0]?.mechanism; |
| 137 | + expect(mockDisable).not.toHaveBeenCalled(); |
| 138 | + expect(mockEnable).toHaveBeenCalledWith( |
| 139 | + expect.objectContaining({ |
| 140 | + allRejections: true, |
| 141 | + onUnhandled: expect.any(Function), |
| 142 | + onHandled: expect.any(Function), |
| 143 | + }), |
| 144 | + ); |
| 145 | + expect(mockEnable).toHaveBeenCalledTimes(1); |
| 146 | + expect((actualSyntheticError as ExtendedError).framesToPop).toBe(3); |
| 147 | + expect(errorMechanism).toEqual({ handled: true, type: 'onunhandledrejection' } as Mechanism); |
| 148 | + }); |
126 | 149 | });
|
127 | 150 | });
|
0 commit comments