From 20f43a3aa95afffd9dea5513b8aae7036bb0b440 Mon Sep 17 00:00:00 2001 From: ziyad-elabid-nw Date: Wed, 19 Jul 2023 17:15:00 +0100 Subject: [PATCH] Update unit test --- packages/react/src/errorboundary.tsx | 2 +- packages/react/test/errorboundary.test.tsx | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/react/src/errorboundary.tsx b/packages/react/src/errorboundary.tsx index bc613c87172f..89f5a1795af2 100644 --- a/packages/react/src/errorboundary.tsx +++ b/packages/react/src/errorboundary.tsx @@ -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(); function recurse(error: Error & { cause?: Error }, cause: Error): void { diff --git a/packages/react/test/errorboundary.test.tsx b/packages/react/test/errorboundary.test.tsx index ef97e07723f2..cac57add55d1 100644 --- a/packages/react/test/errorboundary.test.tsx +++ b/packages/react/test/errorboundary.test.tsx @@ -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(); @@ -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; }