@@ -382,6 +382,43 @@ describe('ErrorBoundary', () => {
382
382
expect ( cause . name ) . not . toContain ( 'React ErrorBoundary' ) ;
383
383
} ) ;
384
384
385
+ it ( 'should truncate cause.message to 250 characters' , ( ) => {
386
+ const mockOnError = jest . fn ( ) ;
387
+
388
+ function CustomBam ( ) : JSX . Element {
389
+ const error = new Error ( 'bam' ) ;
390
+ // The cause message with 610 characters
391
+ const cause = new Error ( 'This is a very long cause message that exceeds 250 characters ' . repeat ( 10 ) ) ;
392
+ // @ts -ignore Need to set cause on error
393
+ error . cause = cause ;
394
+ throw error ;
395
+ }
396
+
397
+ render (
398
+ < TestApp fallback = { < p > You have hit an error</ p > } onError = { mockOnError } errorComp = { < CustomBam /> } >
399
+ < h1 > children</ h1 >
400
+ </ TestApp > ,
401
+ ) ;
402
+
403
+ expect ( mockOnError ) . toHaveBeenCalledTimes ( 0 ) ;
404
+ expect ( mockCaptureException ) . toHaveBeenCalledTimes ( 0 ) ;
405
+
406
+ const btn = screen . getByTestId ( 'errorBtn' ) ;
407
+ fireEvent . click ( btn ) ;
408
+
409
+ expect ( mockCaptureException ) . toHaveBeenCalledTimes ( 1 ) ;
410
+ expect ( mockCaptureException ) . toHaveBeenLastCalledWith ( expect . any ( Error ) , {
411
+ contexts : { react : { componentStack : expect . any ( String ) } } ,
412
+ } ) ;
413
+
414
+ expect ( mockOnError . mock . calls [ 0 ] [ 0 ] ) . toEqual ( mockCaptureException . mock . calls [ 0 ] [ 0 ] ) ;
415
+
416
+ const error = mockCaptureException . mock . calls [ 0 ] [ 0 ] ;
417
+ const cause = error . cause ;
418
+ // We need to make sure that the length of the cause message is 250
419
+ expect ( cause . message ) . toHaveLength ( 250 ) ;
420
+ } ) ;
421
+
385
422
it ( 'calls `beforeCapture()` when an error occurs' , ( ) => {
386
423
const mockBeforeCapture = jest . fn ( ) ;
387
424
0 commit comments