1
1
import { HttpErrorResponse } from '@angular/common/http' ;
2
2
import * as SentryBrowser from '@sentry/browser' ;
3
3
import type { Client , Event } from '@sentry/core' ;
4
- import { vi } from 'vitest' ;
4
+ import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest' ;
5
5
import { createErrorHandler , SentryErrorHandler } from '../src/errorhandler' ;
6
6
7
7
const captureExceptionSpy = vi . spyOn ( SentryBrowser , 'captureException' ) ;
8
8
9
9
vi . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
10
10
11
11
const captureExceptionEventHint = {
12
- mechanism : { handled : false , type : 'angular' } ,
12
+ mechanism : { handled : false , type : 'auto.function. angular.error_handler ' } ,
13
13
} ;
14
14
15
15
class CustomError extends Error {
@@ -71,15 +71,19 @@ describe('SentryErrorHandler', () => {
71
71
createErrorHandler ( ) . handleError ( str ) ;
72
72
73
73
expect ( captureExceptionSpy ) . toHaveBeenCalledTimes ( 1 ) ;
74
- expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( str , { mechanism : { handled : false , type : 'angular' } } ) ;
74
+ expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( str , {
75
+ mechanism : { handled : false , type : 'auto.function.angular.error_handler' } ,
76
+ } ) ;
75
77
} ) ;
76
78
77
79
it ( 'extracts an empty Error' , ( ) => {
78
80
const err = new Error ( ) ;
79
81
createErrorHandler ( ) . handleError ( err ) ;
80
82
81
83
expect ( captureExceptionSpy ) . toHaveBeenCalledTimes ( 1 ) ;
82
- expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( err , { mechanism : { handled : false , type : 'angular' } } ) ;
84
+ expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( err , {
85
+ mechanism : { handled : false , type : 'auto.function.angular.error_handler' } ,
86
+ } ) ;
83
87
} ) ;
84
88
85
89
it ( 'extracts a non-empty Error' , ( ) => {
@@ -88,7 +92,9 @@ describe('SentryErrorHandler', () => {
88
92
createErrorHandler ( ) . handleError ( err ) ;
89
93
90
94
expect ( captureExceptionSpy ) . toHaveBeenCalledTimes ( 1 ) ;
91
- expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( err , { mechanism : { handled : false , type : 'angular' } } ) ;
95
+ expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( err , {
96
+ mechanism : { handled : false , type : 'auto.function.angular.error_handler' } ,
97
+ } ) ;
92
98
} ) ;
93
99
94
100
it ( 'extracts an error-like object without stack' , ( ) => {
@@ -169,7 +175,9 @@ describe('SentryErrorHandler', () => {
169
175
createErrorHandler ( ) . handleError ( err ) ;
170
176
171
177
expect ( captureExceptionSpy ) . toHaveBeenCalledTimes ( 1 ) ;
172
- expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( err , { mechanism : { handled : false , type : 'angular' } } ) ;
178
+ expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( err , {
179
+ mechanism : { handled : false , type : 'auto.function.angular.error_handler' } ,
180
+ } ) ;
173
181
} ) ;
174
182
175
183
it ( 'extracts an instance of class not extending Error but that has an error-like shape' , ( ) => {
@@ -178,7 +186,9 @@ describe('SentryErrorHandler', () => {
178
186
createErrorHandler ( ) . handleError ( err ) ;
179
187
180
188
expect ( captureExceptionSpy ) . toHaveBeenCalledTimes ( 1 ) ;
181
- expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( err , { mechanism : { handled : false , type : 'angular' } } ) ;
189
+ expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( err , {
190
+ mechanism : { handled : false , type : 'auto.function.angular.error_handler' } ,
191
+ } ) ;
182
192
} ) ;
183
193
184
194
it ( 'extracts an instance of a class that does not extend Error and does not have an error-like shape' , ( ) => {
@@ -251,7 +261,9 @@ describe('SentryErrorHandler', () => {
251
261
createErrorHandler ( ) . handleError ( err ) ;
252
262
253
263
expect ( captureExceptionSpy ) . toHaveBeenCalledTimes ( 1 ) ;
254
- expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( ngErr , { mechanism : { handled : false , type : 'angular' } } ) ;
264
+ expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( ngErr , {
265
+ mechanism : { handled : false , type : 'auto.function.angular.error_handler' } ,
266
+ } ) ;
255
267
} ) ;
256
268
257
269
it ( 'extracts an `HttpErrorResponse` with `Error`' , ( ) => {
@@ -261,7 +273,9 @@ describe('SentryErrorHandler', () => {
261
273
createErrorHandler ( ) . handleError ( err ) ;
262
274
263
275
expect ( captureExceptionSpy ) . toHaveBeenCalledTimes ( 1 ) ;
264
- expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( httpErr , { mechanism : { handled : false , type : 'angular' } } ) ;
276
+ expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( httpErr , {
277
+ mechanism : { handled : false , type : 'auto.function.angular.error_handler' } ,
278
+ } ) ;
265
279
} ) ;
266
280
267
281
it ( 'extracts an `HttpErrorResponse` with `ErrorEvent`' , ( ) => {
@@ -431,7 +445,9 @@ describe('SentryErrorHandler', () => {
431
445
createErrorHandler ( ) . handleError ( err ) ;
432
446
433
447
expect ( captureExceptionSpy ) . toHaveBeenCalledTimes ( 1 ) ;
434
- expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( err , { mechanism : { handled : false , type : 'angular' } } ) ;
448
+ expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( err , {
449
+ mechanism : { handled : false , type : 'auto.function.angular.error_handler' } ,
450
+ } ) ;
435
451
} ) ;
436
452
437
453
it ( 'extracts an `HttpErrorResponse` with an instance of class not extending Error but that has an error-like shape' , ( ) => {
@@ -441,7 +457,9 @@ describe('SentryErrorHandler', () => {
441
457
createErrorHandler ( ) . handleError ( err ) ;
442
458
443
459
expect ( captureExceptionSpy ) . toHaveBeenCalledTimes ( 1 ) ;
444
- expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( innerErr , { mechanism : { handled : false , type : 'angular' } } ) ;
460
+ expect ( captureExceptionSpy ) . toHaveBeenCalledWith ( innerErr , {
461
+ mechanism : { handled : false , type : 'auto.function.angular.error_handler' } ,
462
+ } ) ;
445
463
} ) ;
446
464
447
465
it ( 'extracts an `HttpErrorResponse` with an instance of a class that does not extend Error and does not have an error-like shape' , ( ) => {
0 commit comments