@@ -242,7 +242,7 @@ describe('ErrorBoundary', () => {
242
242
captureContext : {
243
243
contexts : { react : { componentStack : expect . any ( String ) } } ,
244
244
} ,
245
- mechanism : { handled : false } ,
245
+ mechanism : { handled : true } ,
246
246
} ) ;
247
247
248
248
expect ( mockOnError . mock . calls [ 0 ] [ 0 ] ) . toEqual ( mockCaptureException . mock . calls [ 0 ] [ 0 ] ) ;
@@ -300,7 +300,7 @@ describe('ErrorBoundary', () => {
300
300
captureContext : {
301
301
contexts : { react : { componentStack : expect . any ( String ) } } ,
302
302
} ,
303
- mechanism : { handled : false } ,
303
+ mechanism : { handled : true } ,
304
304
} ) ;
305
305
306
306
// Check if error.cause -> react component stack
@@ -339,7 +339,7 @@ describe('ErrorBoundary', () => {
339
339
captureContext : {
340
340
contexts : { react : { componentStack : expect . any ( String ) } } ,
341
341
} ,
342
- mechanism : { handled : false } ,
342
+ mechanism : { handled : true } ,
343
343
} ) ;
344
344
345
345
expect ( mockOnError . mock . calls [ 0 ] [ 0 ] ) . toEqual ( mockCaptureException . mock . calls [ 0 ] [ 0 ] ) ;
@@ -383,7 +383,7 @@ describe('ErrorBoundary', () => {
383
383
captureContext : {
384
384
contexts : { react : { componentStack : expect . any ( String ) } } ,
385
385
} ,
386
- mechanism : { handled : false } ,
386
+ mechanism : { handled : true } ,
387
387
} ) ;
388
388
389
389
expect ( mockOnError . mock . calls [ 0 ] [ 0 ] ) . toEqual ( mockCaptureException . mock . calls [ 0 ] [ 0 ] ) ;
@@ -515,6 +515,48 @@ describe('ErrorBoundary', () => {
515
515
expect ( mockOnReset ) . toHaveBeenCalledTimes ( 1 ) ;
516
516
expect ( mockOnReset ) . toHaveBeenCalledWith ( expect . any ( Error ) , expect . any ( String ) , expect . any ( String ) ) ;
517
517
} ) ;
518
+
519
+ it ( 'sets `handled: true` when a fallback is provided' , async ( ) => {
520
+ render (
521
+ < TestApp fallback = { ( { resetError } ) => < button data-testid = "reset" onClick = { resetError } /> } >
522
+ < h1 > children</ h1 >
523
+ </ TestApp > ,
524
+ ) ;
525
+
526
+ expect ( mockCaptureException ) . toHaveBeenCalledTimes ( 0 ) ;
527
+
528
+ const btn = screen . getByTestId ( 'errorBtn' ) ;
529
+ fireEvent . click ( btn ) ;
530
+
531
+ expect ( mockCaptureException ) . toHaveBeenCalledTimes ( 1 ) ;
532
+ expect ( mockCaptureException ) . toHaveBeenLastCalledWith ( expect . any ( Object ) , {
533
+ captureContext : {
534
+ contexts : { react : { componentStack : expect . any ( String ) } } ,
535
+ } ,
536
+ mechanism : { handled : true } ,
537
+ } ) ;
538
+ } ) ;
539
+
540
+ it ( 'sets `handled: false` when no fallback is provided' , async ( ) => {
541
+ render (
542
+ < TestApp >
543
+ < h1 > children</ h1 >
544
+ </ TestApp > ,
545
+ ) ;
546
+
547
+ expect ( mockCaptureException ) . toHaveBeenCalledTimes ( 0 ) ;
548
+
549
+ const btn = screen . getByTestId ( 'errorBtn' ) ;
550
+ fireEvent . click ( btn ) ;
551
+
552
+ expect ( mockCaptureException ) . toHaveBeenCalledTimes ( 1 ) ;
553
+ expect ( mockCaptureException ) . toHaveBeenLastCalledWith ( expect . any ( Object ) , {
554
+ captureContext : {
555
+ contexts : { react : { componentStack : expect . any ( String ) } } ,
556
+ } ,
557
+ mechanism : { handled : false } ,
558
+ } ) ;
559
+ } ) ;
518
560
} ) ;
519
561
} ) ;
520
562
0 commit comments