Last active
January 13, 2021 21:01
-
-
Save mariocsantos/7ba916542633a14cd322738517e84730 to your computer and use it in GitHub Desktop.
Favorite food test mock prop
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 { FavoriteFood } from '../FavoriteFood'; | |
describe('FavoriteFood', () => { | |
it('should submit form', () => { | |
const onSubmitMock = jest.fn(); | |
render(<FavoriteFood onSubmit={onSubmitMock} />); | |
const input = screen.getByLabelText(/Favorite food/i); | |
userEvent.type(input, 'Taco 🌮'); | |
const button = screen.getByRole('button'); | |
userEvent.click(button); | |
expect(onSubmitMock).toHaveBeenCalled(); | |
expect(onSubmitMock).toHaveBeenCalledTimes(1); | |
expect(onSubmitMock).toHaveBeenCalledWith('Taco 🌮'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment