Fail tests that have unexpected API requests
See original GitHub issueIs 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 a force404
, but that’s not enough to be able to actually cause a test to fail
I had thought of using the onResponse
option but it gets bypassed for the requests that force404
handles.
cy.server({
force404: true,
onResponse: xhr => {
if (xhr.status === 404) {
expect(true).to.equal(false);
}
}
});
Issue Analytics
- State:
- Created 6 years ago
- Reactions:7
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Fail a test in Jest if an unexpected network request happens
It usually means that there were pending asynchronous requests when the test finished. Our first attempt at catching errors. We have this ...
Read more >4 common API errors and how to test them
API failures are inevitable; the important part is how quickly you can react. Here are 4 common API failures, and how you can...
Read more >Top 3 Reasons for API Failures
One great way to prevent API failures is by running API testing and monitoring to track performance.
Read more >8 Common API Error Examples and Use Cases - Rapid Blog
8 Common API Error Examples and Use Cases · 2. Outdated Caching · 3. Unexpected error codes · 5. Sending invalid authorization credentials...
Read more >[BUG] did something change on APIRequest/Response APIs
Context: Playwright Version: 1.19 is failing some tests, ... 'PUT' and 'TRACE' requests we don't read response body as they don't have one ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.