@@ -305,29 +305,78 @@ describe('CaptureConsole setup', () => {
305305 } ) . not . toThrow ( ) ;
306306 } ) ;
307307
308- it ( "marks captured exception's mechanism as unhandled" , ( ) => {
309- // const addExceptionMechanismSpy = jest.spyOn(utils, 'addExceptionMechanism');
308+ describe ( 'exception mechanism' , ( ) => {
309+ // TODO (v9): Flip this below after adjusting the default value for `handled` in the integration
310+ it ( "marks captured exception's mechanism as unhandled by default" , ( ) => {
311+ const captureConsole = captureConsoleIntegration ( { levels : [ 'error' ] } ) ;
312+ captureConsole . setup ?.( mockClient ) ;
310313
311- const captureConsole = captureConsoleIntegration ( { levels : [ ' error'] } ) ;
312- captureConsole . setup ?. ( mockClient ) ;
314+ const someError = new Error ( 'some error') ;
315+ GLOBAL_OBJ . console . error ( someError ) ;
313316
314- const someError = new Error ( 'some error' ) ;
315- GLOBAL_OBJ . console . error ( someError ) ;
317+ const addedEventProcessor = ( mockScope . addEventProcessor as jest . Mock ) . mock . calls [ 0 ] [ 0 ] ;
318+ const someEvent : Event = {
319+ exception : {
320+ values : [ { } ] ,
321+ } ,
322+ } ;
323+ addedEventProcessor ( someEvent ) ;
316324
317- const addedEventProcessor = ( mockScope . addEventProcessor as jest . Mock ) . mock . calls [ 0 ] [ 0 ] ;
318- const someEvent : Event = {
319- exception : {
320- values : [ { } ] ,
321- } ,
322- } ;
323- addedEventProcessor ( someEvent ) ;
325+ expect ( captureException ) . toHaveBeenCalledTimes ( 1 ) ;
326+ expect ( mockScope . addEventProcessor ) . toHaveBeenCalledTimes ( 1 ) ;
324327
325- expect ( captureException ) . toHaveBeenCalledTimes ( 1 ) ;
326- expect ( mockScope . addEventProcessor ) . toHaveBeenCalledTimes ( 1 ) ;
328+ expect ( someEvent . exception ?. values ?. [ 0 ] ?. mechanism ) . toEqual ( {
329+ handled : false ,
330+ type : 'console' ,
331+ } ) ;
332+ } ) ;
333+
334+ it ( "marks captured exception's mechanism as handled if set in the options" , ( ) => {
335+ const captureConsole = captureConsoleIntegration ( { levels : [ 'error' ] , handled : true } ) ;
336+ captureConsole . setup ?.( mockClient ) ;
327337
328- expect ( someEvent . exception ?. values ?. [ 0 ] ?. mechanism ) . toEqual ( {
329- handled : false ,
330- type : 'console' ,
338+ const someError = new Error ( 'some error' ) ;
339+ GLOBAL_OBJ . console . error ( someError ) ;
340+
341+ const addedEventProcessor = ( mockScope . addEventProcessor as jest . Mock ) . mock . calls [ 0 ] [ 0 ] ;
342+ const someEvent : Event = {
343+ exception : {
344+ values : [ { } ] ,
345+ } ,
346+ } ;
347+ addedEventProcessor ( someEvent ) ;
348+
349+ expect ( captureException ) . toHaveBeenCalledTimes ( 1 ) ;
350+ expect ( mockScope . addEventProcessor ) . toHaveBeenCalledTimes ( 1 ) ;
351+
352+ expect ( someEvent . exception ?. values ?. [ 0 ] ?. mechanism ) . toEqual ( {
353+ handled : true ,
354+ type : 'console' ,
355+ } ) ;
356+ } ) ;
357+
358+ it ( "marks captured exception's mechanism as unhandled if set in the options" , ( ) => {
359+ const captureConsole = captureConsoleIntegration ( { levels : [ 'error' ] , handled : false } ) ;
360+ captureConsole . setup ?.( mockClient ) ;
361+
362+ const someError = new Error ( 'some error' ) ;
363+ GLOBAL_OBJ . console . error ( someError ) ;
364+
365+ const addedEventProcessor = ( mockScope . addEventProcessor as jest . Mock ) . mock . calls [ 0 ] [ 0 ] ;
366+ const someEvent : Event = {
367+ exception : {
368+ values : [ { } ] ,
369+ } ,
370+ } ;
371+ addedEventProcessor ( someEvent ) ;
372+
373+ expect ( captureException ) . toHaveBeenCalledTimes ( 1 ) ;
374+ expect ( mockScope . addEventProcessor ) . toHaveBeenCalledTimes ( 1 ) ;
375+
376+ expect ( someEvent . exception ?. values ?. [ 0 ] ?. mechanism ) . toEqual ( {
377+ handled : false ,
378+ type : 'console' ,
379+ } ) ;
331380 } ) ;
332381 } ) ;
333382} ) ;
0 commit comments