Skip to content

Commit 20f43a3

Browse files
Update unit test
1 parent 2c37943 commit 20f43a3

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

packages/react/src/errorboundary.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const INITIAL_STATE = {
6767
eventId: null,
6868
};
6969

70-
function setCause(error: Error & { cause?: Error }, cause: Error): void {
70+
export function setCause(error: Error & { cause?: Error }, cause: Error): void {
7171
const seenErrors = new WeakMap<Error, boolean>();
7272

7373
function recurse(error: Error & { cause?: Error }, cause: Error): void {

packages/react/test/errorboundary.test.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as React from 'react';
44
import { useState } from 'react';
55

66
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';
88

99
const mockCaptureException = jest.fn();
1010
const mockShowReportDialog = jest.fn();
@@ -382,15 +382,14 @@ describe('ErrorBoundary', () => {
382382
expect(cause.name).not.toContain('React ErrorBoundary');
383383
});
384384

385-
it('should truncate cause.message to 250 characters', () => {
385+
it('should truncate cause.message to maxLengthValue = 250 ', () => {
386386
const mockOnError = jest.fn();
387387

388388
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
391391
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);
394393
throw error;
395394
}
396395

0 commit comments

Comments
 (0)