-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fail tests that have unexpected API requests #910
Comments
Still wasn't able to find a way to cause a test to fail if the |
Any news about this, I'd love to see this happen. Is there a lot of work ? I can work on if not |
So, am I missing something, or is there actually no way to check that no request during the test returned with 500 status code? If my backend responds with 500, then there's definitely an issue that I'd like to fix, so I want the test to fail. |
I also ran into this. In my case, I had a test that was submitting a form, but due to a bug in the backend code under test, the server replied with a 403. Because I didn't actually assert anything about the response HTML, that test was passing when it shouldn't have. I can update the test to look for something specific in a correct response, but it'd be great to have the test automatically fail in that scenario. |
Hi everyone, this is possible to do with // block all HTTP requests
cy.intercept('*', (req) => {
throw new Error(`Received an unexpected request to ${req.url}!`)
})
// allow some expected requests
cy.intercept('/api', (req) => {
// call `req.continue()` to stop the request from propagating to the block handler
req.continue()
}) Closing since this is now possible. |
Is this a Feature or Bug?
Feature
Desired behavior:
I'd like a way to fail a test for any XHR calls that are not expected (ie. that no
cy.route()
has been set for). Current there's aforce404
, but that's not enough to be able to actually cause a test to failI had thought of using the
onResponse
option but it gets bypassed for the requests thatforce404
handles.The text was updated successfully, but these errors were encountered: