Skip to content

Instantly share code, notes, and snippets.

@yanmendes
Last active August 2, 2019 20:13
Show Gist options
  • Save yanmendes/b0e2f574f8d5ff141dbd75ac6987784e to your computer and use it in GitHub Desktop.
Save yanmendes/b0e2f574f8d5ff141dbd75ac6987784e to your computer and use it in GitHub Desktop.
import { render, fireEvent } from '@testing-library/react'
test('should submit a valid form', () => {
const { getByLabelText, getByText } = render(<App />)
const setValue = value => ({ target: { value } })
const password = '123456'
const email = 'foo@bar.com'
fireEvent.input(getByLabelText('Email'), setValue(email))
fireEvent.input(getByLabelText('Password'), setValue(password))
fireEvent.input(getByLabelText('Confirm your password'), setValue(password))
fireEvent.click(getByText('Submit'))
expect(axios.post).toHaveBeenCalledWith('http://localhost:5000', {
email,
password
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment