|
1 | 1 | /* eslint-disable @typescript-eslint/unbound-method */
|
2 | 2 | import type { Event, Hub, Integration } from '@sentry/types';
|
3 | 3 | import type { ConsoleLevel } from '@sentry/utils';
|
| 4 | +// import * as utils from '@sentry/utils'; |
4 | 5 | import { addInstrumentationHandler, CONSOLE_LEVELS, GLOBAL_OBJ, originalConsoleMethods } from '@sentry/utils';
|
5 | 6 |
|
6 | 7 | import { CaptureConsole } from '../src/captureconsole';
|
@@ -389,4 +390,36 @@ describe('CaptureConsole setup', () => {
|
389 | 390 | GLOBAL_OBJ.console.log('some message');
|
390 | 391 | }).not.toThrow();
|
391 | 392 | });
|
| 393 | + |
| 394 | + it("marks captured exception's mechanism as unhandled", () => { |
| 395 | + // const addExceptionMechanismSpy = jest.spyOn(utils, 'addExceptionMechanism'); |
| 396 | + |
| 397 | + const captureConsoleIntegration = new CaptureConsole({ levels: ['error'] }); |
| 398 | + const mockHub = getMockHub(captureConsoleIntegration); |
| 399 | + captureConsoleIntegration.setupOnce( |
| 400 | + () => undefined, |
| 401 | + () => mockHub, |
| 402 | + ); |
| 403 | + |
| 404 | + const mockScope = mockHub.getScope(); |
| 405 | + |
| 406 | + const someError = new Error('some error'); |
| 407 | + GLOBAL_OBJ.console.error(someError); |
| 408 | + |
| 409 | + const addedEventProcessor = (mockScope.addEventProcessor as jest.Mock).mock.calls[0][0]; |
| 410 | + const someEvent: Event = { |
| 411 | + exception: { |
| 412 | + values: [{}], |
| 413 | + }, |
| 414 | + }; |
| 415 | + addedEventProcessor(someEvent); |
| 416 | + |
| 417 | + expect(mockHub.captureException).toHaveBeenCalledTimes(1); |
| 418 | + expect(mockScope.addEventProcessor).toHaveBeenCalledTimes(1); |
| 419 | + |
| 420 | + expect(someEvent.exception?.values?.[0].mechanism).toEqual({ |
| 421 | + handled: false, |
| 422 | + type: 'console', |
| 423 | + }); |
| 424 | + }); |
392 | 425 | });
|
0 commit comments