Skip to content

Commit

Permalink
Update unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ziyad-elabid-nw committed Jul 19, 2023
1 parent 2c37943 commit 20f43a3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/react/src/errorboundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const INITIAL_STATE = {
eventId: null,
};

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

function recurse(error: Error & { cause?: Error }, cause: Error): void {
Expand Down
11 changes: 5 additions & 6 deletions packages/react/test/errorboundary.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as React from 'react';
import { useState } from 'react';

import type { ErrorBoundaryProps } from '../src/errorboundary';
import { ErrorBoundary, isAtLeastReact17, UNKNOWN_COMPONENT, withErrorBoundary } from '../src/errorboundary';
import { ErrorBoundary, isAtLeastReact17, setCause, UNKNOWN_COMPONENT, withErrorBoundary } from '../src/errorboundary';

const mockCaptureException = jest.fn();
const mockShowReportDialog = jest.fn();
Expand Down Expand Up @@ -382,15 +382,14 @@ describe('ErrorBoundary', () => {
expect(cause.name).not.toContain('React ErrorBoundary');
});

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

function CustomBam(): JSX.Element {
const error = new Error('bam');
// The cause message with 610 characters
const error = new Error('Error example');
// The cause message with 620 characters
const cause = new Error('This is a very long cause message that exceeds 250 characters '.repeat(10));
// @ts-ignore Need to set cause on error
error.cause = cause;
setCause(error, cause);
throw error;
}

Expand Down

0 comments on commit 20f43a3

Please sign in to comment.