-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Intercepted calls are queued before cy.wait #14703
Comments
I believe this feature request might satisfy what you're asking for? #7663 If so, please add your comments and 👍 on that issue since we use interest in the feature to evaluate priority of development. Couldn't you also be more specific with the intercept you want to listen for? Defining the path you want to listen for to be it('processes the intercepted requests in a queue', () => {
cy.visit(baseUrl);
// path: people/10
cy.intercept({method: 'GET', path: '/api/people/10'}).as('getPeople')
//...
// this is a call I want to interact with
.wait('@getPeople').then((req) => {
const returnedUrl = String(req.response.body.url);
expect(returnedUrl).to.contain('people/10/'); // we only intercepted people/10 route
});
}); |
Hi! Thank you for your response. The #7663 would solve the issue partially - but ideally we would like to not depend on the number of times the interception matched prior to the call that the code is waiting for (possibly if passing -1 as n would always select the last interception, then it would solve it entirely). As for increasing path specificity, that can also work, but sometimes the full path might be difficult to obtain ("randomly" created new ID) or there might even be the same path called repeatedly but with different responses. |
Hey @vojta-k, this is the expected behavior of
Does per-request aliasing solve this for you? You can dynamically set an alias from a request handler, so you could test for your randomly created ID/whatever: https://docs.cypress.io/api/commands/intercept#Aliasing-individual-requests |
Closing since all appears to be working as expected. Please open an issue if you have a new bug report or feature request. |
@flotwig @jennifer-shehane I believe this issue should be open again as it is a bug and doesn't work as expected according to cypress official documentation here: Network Requests - waiting
|
Current behavior
After calling an intercept for method and path and assigning it an alias, all calls intercepted in this manner are stored in a queue form rather than stacked as I would expect. Meaning if 2 such calls are intercepted but the first one isn't interacted with via
.wait(<alias>)
, then interacting with the second call in this way will return information from the first one instead.In larger, more complex app and testing code base, it is easy to unintentionally intercept a different, unwanted call prior to interacting with the desired one. So this behaviour is not ideal for that.
Desired behavior
Intercepted call should be rather stacked or possible those that aren't being interacted with forgotten. Maybe ideally there should be an option parameter to define which of these approaches will be used.
Test code to reproduce
Versions
Cypress version 6.2.1
Browser Chrome 88
The text was updated successfully, but these errors were encountered: