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.route() unable to mock same url multiple times if requests happen quickly

See original GitHub issue

Current behavior:

If you make multiple requests to the same endpoint and want to mock each response differently based on the order that they occur, cypress appears to be unable to do it unless you wait X milliseconds between requests. If there is no pause between requests, cypress will never catch the first cy.wait(...) and will mock every request to that endpoint with the same response.

Desired behavior:

cy.server()
cy.route(url, res1).as(get)
cy.wait(@get)
cy.route(url, res2).as(get)

Should result in the first GET request to url responding with res1 and the second GET request to url responding with res2, regardless of the amount of time between requests.

Steps to reproduce: (app code and test code)

Run tests here

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:171
  • Comments:67 (7 by maintainers)

github_iconTop GitHub Comments

37reactions
TheBestPessimistcommented, Apr 15, 2020

@ folks who have the same issue, please don’t forget to 👍 the OP. It’s easier to see how many people are interested in this by seeing the 👍 number. It’s also pretty difficult to read the comment discussion if all we see is rounds and rounds of “me too” “me too”.

36reactions
mpvossellercommented, Jul 18, 2019

Same. Need a way to specify the response of the Nth request.

Read more comments on GitHub >

github_iconTop Results From Across the Web

cy.intercept() unable to mock the same url multiple times
cy.intercept() mocks the response first time. But, if I try again second time with a different response, it does not work.
Read more >
Network Requests - Cypress Documentation
If the circle is solid, the request went to the destination server; if it is outlined, the response was stubbed by cy.intercept() and...
Read more >
Cypress cy.intercept Problems - Gleb Bahmutov
The command cy.intercept can match requests using a substring, a minimatch, or a regular expression. By default, it intercepts requests matching ...
Read more >
A Practical Guide to Intercepting Network Requests in Cypress
First things first - matching our url. When using .intercept() command, there are two main questions that need to be resolved. How do...
Read more >
Mocking HTTP Calls in Cypress End-to-End Tests
The as('getCartItems'); code at the end of the cy.route() call is an alias ... the same mocked route and returning different data each...
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