question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fail tests that have unexpected API requests

See original GitHub issue

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 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:closed
  • Created 6 years ago
  • Reactions:7
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
TomPradatcommented, Jan 20, 2020

Any news about this, I’d love to see this happen. Is there a lot of work ? I can work on if not

4reactions
AlexDanielcommented, Jun 17, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found