Subject Under Test(sut):
An error fallback component to be passed to ErrorBoundary component from react-error-boundary.
Behaviours:
In development mode, it shows error track trace
In production mode, it hides error track trace
It shows a
Resetbutton, and clicking it calls resetErrorBoundary action passed by parentErrorBoundarycomponent.
Code
Notes
- The
renderInErrorBoundaryhelper method renders a bomb component inside an actualErrorBoundary, no mocks. It shows how the sut should be used. -
getByTextitself implicitly asserts if the element is in the document because if not found, it will throw an error. However, I asserted anyway for clarity -
queryByTestIdis used to assert if the error stack trace is rendered in the DOM under production, it returns null if not found, contrary togetByTestId, which would throw an error when the element is not found. -
@epic/environmentsis mocked out to override the value to test production mode behaviour. - The
renderStandalonehelper method renders the component as any other React component, for the sole purpose of testing the behaviour of theResetbutton. Because theresetErrorBoundaryis implicitly passed to the sut, and I don’t know a way to mock a React component prop yet. The test shouldn’t care about it anyway.
Top comments (0)