Skip to content

Instantly share code, notes, and snippets.

@albertBarsegyan
Created September 2, 2021 14:18
Show Gist options
  • Save albertBarsegyan/273548b967ff6f10444a8dd9131772b4 to your computer and use it in GitHub Desktop.
Save albertBarsegyan/273548b967ff6f10444a8dd9131772b4 to your computer and use it in GitHub Desktop.
Form failure test
it('Failure test', async () => {
const handleSubmit = jest.fn();
render(<CompanyForm onSubmit={handleSubmit} />);
const submitButton = screen.getByTestId('companyFormSubmitButton');
const nameError = screen.getByTestId('nameError');
const emailError = screen.queryByTestId('emailError');
const phoneNumberError = screen.queryByTestId('phoneNumberError');
const agreementError = screen.queryByTestId('agreementError');
userEvent.click(submitButton);
// all inputs are empty
// it means every input and checkbox will show error message
await waitFor(() => {
expect(emailError.textContent).toMatch(
formTestConstants.errorMessageForEmail,
);
expect(nameError.textContent).toMatch(
formTestConstants.errorMessageForName,
);
expect(phoneNumberError.textContent).toMatch(
formTestConstants.errorMessageForPhone,
);
expect(agreementError.textContent).toMatch(
formTestConstants.errorMessageForAgreement,
);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment