Created
September 2, 2021 14:18
-
-
Save albertBarsegyan/273548b967ff6f10444a8dd9131772b4 to your computer and use it in GitHub Desktop.
Form failure test
This file contains hidden or 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
| 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