cy.route() unable to mock same url multiple times if requests happen quickly
See original GitHub issueCurrent 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:
- Created 4 years ago
- Reactions:171
- Comments:67 (7 by maintainers)
Top 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 >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 FreeTop 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
Top GitHub Comments
@ 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”.
Same. Need a way to specify the response of the Nth request.