From 0c4489574b5c6738c514faba86dee5ea2ee70b68 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Fri, 8 Mar 2024 14:24:03 +0100 Subject: [PATCH] fix(react): Set `handled` value in ErrorBoundary depending on fallback --- packages/react/src/errorboundary.tsx | 4 +- packages/react/test/errorboundary.test.tsx | 50 ++++++++++++++++++++-- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/packages/react/src/errorboundary.tsx b/packages/react/src/errorboundary.tsx index 2a599d24e7aa..04794f15bd65 100644 --- a/packages/react/src/errorboundary.tsx +++ b/packages/react/src/errorboundary.tsx @@ -146,7 +146,9 @@ class ErrorBoundary extends React.Component { captureContext: { contexts: { react: { componentStack: expect.any(String) } }, }, - mechanism: { handled: false }, + mechanism: { handled: true }, }); expect(mockOnError.mock.calls[0][0]).toEqual(mockCaptureException.mock.calls[0][0]); @@ -300,7 +300,7 @@ describe('ErrorBoundary', () => { captureContext: { contexts: { react: { componentStack: expect.any(String) } }, }, - mechanism: { handled: false }, + mechanism: { handled: true }, }); // Check if error.cause -> react component stack @@ -339,7 +339,7 @@ describe('ErrorBoundary', () => { captureContext: { contexts: { react: { componentStack: expect.any(String) } }, }, - mechanism: { handled: false }, + mechanism: { handled: true }, }); expect(mockOnError.mock.calls[0][0]).toEqual(mockCaptureException.mock.calls[0][0]); @@ -383,7 +383,7 @@ describe('ErrorBoundary', () => { captureContext: { contexts: { react: { componentStack: expect.any(String) } }, }, - mechanism: { handled: false }, + mechanism: { handled: true }, }); expect(mockOnError.mock.calls[0][0]).toEqual(mockCaptureException.mock.calls[0][0]); @@ -515,6 +515,48 @@ describe('ErrorBoundary', () => { expect(mockOnReset).toHaveBeenCalledTimes(1); expect(mockOnReset).toHaveBeenCalledWith(expect.any(Error), expect.any(String), expect.any(String)); }); + + it('sets `handled: true` when a fallback is provided', async () => { + render( +