I have an application using React and axios, and I want to this the following behvior:
- Fill a form
- submit form
- Success message shows
- Fill the form again
- submit form
- While the request is made, the success message should not be showing**
- request finish, success message shows again
**the problem is to test this step (6)
I'm using axios-mock-adapter
to mock axios. I tried the following approach:
axiosMock
.onPost('/api/auth/alteracaoSenha').replyOnce(204)
.onPost('/api/auth/alteracaoSenha').replyOnce(() => {
expect(screen.queryByText('Success message')).not.toBeInTheDocument()
return [204]
})
When I try this, it works fine. But, if I remove the code that reset the success message to see if the test broke, the test continues to pass. What I found is that the expect throws an error, but the axios mock catch this error and just return it to the API :/ So the expect line that should file, did not break the test.
Is there any other option to do that test?