Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- window.alert = jest.fn();
- expect(window.alert).toHaveBeenCalledTimes(1);
- async handleSubmit(event: React.FormEvent<HTMLFormElement>) {
- // check for errors
- if (errors) {
- window.alert('Some Error occurred');
- return;
- }
- }
- it('alerts on submit click', async () => {
- const alertMock = jest.spyOn(window,'alert');
- const { getByText, getByTestId } = render(<Form />)
- fireEvent.click(getByText('Submit'))
- expect(alertMock).toHaveBeenCalledTimes(1)
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement