Created
October 4, 2020 23:18
-
-
Save OlaoluwaM/947a805cc6ffc0abd84f0cbe9b21c7cc to your computer and use it in GitHub Desktop.
Async test example with act function
This file contains hidden or 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
test('should let user know their input was invalid or incorrect', async () => { | |
const {findByPlaceholderText, findByTestId} = render(<AuthComp />) // Or whatever you call you authentication component | |
const inputElement = await findByPlaceholderText('Age') // any query function prefixed with findBy* is asynchronous | |
await act(async () => { | |
fireEvent.input(inputElement, {target: {value: 12}}) | |
}) | |
const validationErrorElement = await findByTestId('validation-error'); | |
expect(validationErrorElement).toHaveTextContent('You are too young') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment