Created
February 1, 2023 03:26
-
-
Save vinnymac/5720fb05a1d18de1df54046c4ac7f240 to your computer and use it in GitHub Desktop.
React error boundary spec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { render, screen } from '@testing-library/react'; | |
import userEvent from '@testing-library/user-event' | |
import { Account } from './Account'; | |
import { ErrorBoundary } from './ErrorBoundary'; | |
describe('Account', () => { | |
it('renders a fallback when an account error is thrown', async () => { | |
const fallback = jest.fn(() => ( | |
<button>Try Again</button> | |
)); | |
const user = userEvent.setup(); | |
render( | |
<ErrorBoundary fallback={fallback}> | |
<Account /> | |
</ErrorBoundary> | |
); | |
await userEvent.click(screen.getByRole('button', { name: /try again/i }); | |
expect(fallback).toHaveBeenCalledTimes(1); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment