Skip to content

Instantly share code, notes, and snippets.

@OlaoluwaM
Created October 4, 2020 23:18
Show Gist options
  • Save OlaoluwaM/947a805cc6ffc0abd84f0cbe9b21c7cc to your computer and use it in GitHub Desktop.
Save OlaoluwaM/947a805cc6ffc0abd84f0cbe9b21c7cc to your computer and use it in GitHub Desktop.
Async test example with act function
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