diff --git a/packages/react/src/errorboundary.tsx b/packages/react/src/errorboundary.tsx index 91cc0e2cdc17..7c983f4599b5 100644 --- a/packages/react/src/errorboundary.tsx +++ b/packages/react/src/errorboundary.tsx @@ -35,6 +35,12 @@ export type ErrorBoundaryProps = { * */ fallback?: React.ReactElement | FallbackRender | undefined; + /** + * If set to `true` or `false`, the error `handled` property will be set to the given value. + * If unset, the default behaviour is to rely on the presence of the `fallback` prop to determine + * if the error was handled or not. + */ + handled?: boolean | undefined; /** Called when the error boundary encounters an error */ onError?: ((error: unknown, componentStack: string | undefined, eventId: string) => void) | undefined; /** Called on componentDidMount() */ @@ -107,7 +113,8 @@ class ErrorBoundary extends React.Component { expect(mockOnReset).toHaveBeenCalledTimes(1); expect(mockOnReset).toHaveBeenCalledWith(expect.any(Error), expect.any(String), expect.any(String)); }); + it.only.each` + fallback | handled | expected + ${true} | ${undefined} | ${true} + ${false} | ${undefined} | ${false} + ${true} | ${false} | ${false} + ${true} | ${true} | ${true} + ${false} | ${true} | ${true} + ${false} | ${false} | ${false} + `( + 'sets `handled: $expected` when `handled` is $handled and `fallback` is $fallback', + async ({ + fallback, + handled, + expected, + }: { + fallback: boolean; + handled: boolean | undefined; + expected: boolean; + }) => { + const fallbackComponent: FallbackRender | undefined = fallback + ? ({ resetError }) =>