@@ -4,7 +4,7 @@ import * as React from 'react';
4
4
import { useState } from 'react' ;
5
5
6
6
import type { ErrorBoundaryProps } from '../src/errorboundary' ;
7
- import { ErrorBoundary , isAtLeastReact17 , UNKNOWN_COMPONENT , withErrorBoundary } from '../src/errorboundary' ;
7
+ import { ErrorBoundary , isAtLeastReact17 , setCause , UNKNOWN_COMPONENT , withErrorBoundary } from '../src/errorboundary' ;
8
8
9
9
const mockCaptureException = jest . fn ( ) ;
10
10
const mockShowReportDialog = jest . fn ( ) ;
@@ -382,15 +382,14 @@ describe('ErrorBoundary', () => {
382
382
expect ( cause . name ) . not . toContain ( 'React ErrorBoundary' ) ;
383
383
} ) ;
384
384
385
- it ( 'should truncate cause.message to 250 characters ' , ( ) => {
385
+ it ( 'should truncate cause.message to maxLengthValue = 250 ' , ( ) => {
386
386
const mockOnError = jest . fn ( ) ;
387
387
388
388
function CustomBam ( ) : JSX . Element {
389
- const error = new Error ( 'bam ' ) ;
390
- // The cause message with 610 characters
389
+ const error = new Error ( 'Error example ' ) ;
390
+ // The cause message with 620 characters
391
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 ;
392
+ setCause ( error , cause ) ;
394
393
throw error ;
395
394
}
396
395
@@ -415,8 +414,8 @@ describe('ErrorBoundary', () => {
415
414
416
415
const error = mockCaptureException . mock . calls [ 0 ] [ 0 ] ;
417
416
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 ) ;
417
+ // We need to make sure that the length of the cause message is 253 (3 characters of etc sign (...) in the truncate function)
418
+ expect ( cause . message ) . toHaveLength ( 253 ) ;
420
419
} ) ;
421
420
422
421
it ( 'calls `beforeCapture()` when an error occurs' , ( ) => {
0 commit comments