I'm stuck trying to run a test as a registered and logged in user with a custom command that sends a POST request and body.
Then in the test suite in a beforeEach hook I try to create user and then log in:
beforeEach(() => {
cy.createUser().then((user) => {
cy.login(user);
});
});
Whenever I run the test cypress trhows error:
CypressError: `cy.request()` failed on:
http://localhost:3000/register
The response we received from your web server was:
> 404: Not Found
This was considered a failure because the status code was not `2xx` or `3xx`.
If you do not want status codes to cause failures pass the option: `failOnStatusCode: false`
This is what I do inside the custom command:
cy.visit('/').then(() => {
cy.request({
url: '/register',
method: 'POST',
body: user,
}).then((response) => ({ ...response.body.user, ...user }));
});
Why is this happening ? Please any feedback will be greatly appreciated.
I've also tried with the flag failOnStatusCode: false
but didn't work.
Many thanks.