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.

cy.wait() non-deterministically times out when waiting for mocked responses: No response ever occurred.

See original GitHub issue

Current behavior:

Sometimes, cy.wait() times out when waiting for some nth response of a mocked out endpoint, even though the Cypress UI shows that the request was stubbed out.

Desired behavior:

The documentation for cy.wait() says:

Each time we use cy.wait() for an alias, Cypress waits for the next nth matching request.

It seems that this behavior should be deterministic and the nth call to cy.wait() should find the nth response of a mocked endpoint if n responses have been successfully stubbed out.

Steps to reproduce:

  1. Mock out an API response, and simulate n calls using that endpoint
  2. Queue n cy.wait() calls (either by manually calling cy.wait() n times, or cy.wait([alias, alias, ..., alias])
  3. This test should always pass, but sometimes the test will fail due a timeout while waiting for one of the responses

Versions

3.0.2, Mac OSX El Capitan, Chrome 67

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

10reactions
michaelsharpecommented, Nov 21, 2018

I am currently experiencing a similar issue. Random tests across our test suite fail on a cy.wait, but it only happens in our CI environment, not when running things locally. I can run the same test suite three times, and of the three two fail and one passes; of the two failing, they each fail in different test suites, but both from waiting on cy.wait commands that never returned.

My current theory is that some responses are so fast that cypress doesn’t have time to hook in. The main difference from our CI environment to our local development is that the CI environment is entirely inside docker. API server, DB, static server that serves the client, and cypress. The docker network connections may be so fast on some responses that it is missed by Cypress.

That is my going theory, at least. I don’t have time to do a minimal reproduction, but I will try to make some time in the next few days. I think setting it all up inside docker-compose should make for a reproducible demonstration of the bug.

4reactions
jennifer-shehanecommented, Jul 30, 2018

There is a difference between manually calling cy.wait() n times and using cy.wait([alias, alias, ..., alias])

Each cy.wait() command has a default requestTimeout of 5000 ms and a default responseTimeout of 30000. This means:

Scenario 1

cy.wait('@alias1') // waits 30 seconds to respond
cy.wait('@alias1') // waits 30 seconds to respond 2nd time
cy.wait('@alias1') // waits 30 seconds to respond 3rd time
cy.wait('@alias1') // waits 30 seconds to respond 4th time

Scenario 2

cy.wait(['@alias1', '@alias1', '@alias1', '@alias1']) // waits 30 seconds for request to respond 4 times

I find the behavior in Scenario 2 to be incredibly confusing - as I myself had many response timeouts seemingly for no reason until I discovered this was the case. I’ve since changed nearly all of my cy.wait() to be chained, like in Scenario 1, rendering the Scenario 2 usage pretty much useless.

Proposal

In order to fix this behavior, I would ideally want the timeouts to apply to each defined alias within the array individually.


@lawsumisu Please let me know if this is not the case and there is also a non-deterministic timeout when serially defining the cy.wait().

Read more comments on GitHub >

github_iconTop Results From Across the Web

wait - Cypress Documentation
Wait automatically increments responses. Each time we use cy.wait() for an alias, Cypress waits for the next nth matching request. // stub an...
Read more >
Cypress intercept - No request ever occurred - Stack Overflow
I am trying to validate this with cypress but it throws ' Timed out retrying after 30000ms: cy.wait() timed out waiting 30000ms for...
Read more >
Waiting in Cypress and how to avoid it - Filip Hric
wait() command in Cypress and halt the test for a couple of seconds. If this applies to you as well, then you know...
Read more >
How to wait for a request to finish before moving on with Cypress
ERROR: Timed out retrying after 5000ms: cy.wait() timed out waiting 5000ms for the 1st request to the route: file. No request ever occurred....
Read more >
Pragmatic Unit Testing
system's idea of “current time” to cause events to happen that you'd have to wait around for ... calls your own getTime() and...
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