Created
November 5, 2020 15:06
-
-
Save vercetti11/c4c6318705dbaf9fab39f02d81dd4df6 to your computer and use it in GitHub Desktop.
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 faker from 'faker' | |
import Login from '../../components/login' | |
function buildLoginForm(overrides) { | |
return { | |
username: faker.internet.userName(), | |
password: faker.internet.password(), | |
...overrides, | |
} | |
} | |
test('submitting the form calls onSubmit with username and password', () => { | |
const handleSubmit = jest.fn() | |
render(<Login onSubmit={handleSubmit} />) | |
const {username, password} = buildLoginForm() | |
userEvent.type(screen.getByLabelText(/username/i), username) | |
userEvent.type(screen.getByLabelText(/password/i), password) | |
userEvent.click(screen.getByRole('button', {name: /submit/i})) | |
expect(handleSubmit).toHaveBeenCalledWith({ | |
username, | |
password, | |
}) | |
expect(handleSubmit).toHaveBeenCalledTimes(1) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment