-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Cypress doesn't match the newest route stub when url matches previous route #3248
Comments
The alias does indeed match the first route found that it matches. We would have to think about changing this behavior. For now, you should likely update your route |
There are several workarounds that I can do indeed, just that the behavior that would seem more intuitive is that the newest route matching the path would be triggered and not the oldest (aka "first"). This is more intuitive for several reasons:
If I explicitly write a route in one of my tests that consume a shared logic, I expect my route (which is newer) to take precedence. (This is actually the case I have right now, that I now need to edit shared testing code because of the route match order). |
Also related to this issue - I was looking for a way to cancel/remove a Is such a thing possible? |
@nitzansan Thanks for the thorough explanation for this feature. We'll have to discuss this proposal and the potential impact of these changes as a team.
This is a good question. You want to remove the alias |
I want to remove the entire cy.route() assignment based on it's alias or exact path. |
Another find regarding this issue - apparently when passing a regex to cy.route it has precedence over glob patterns and regex pattern routes indeed match in the expected behavior (newer beats older). cy.route('mysite.com/entitiesCollection**', response1).as('firstCall');
// something happens here that triggers the call to the relevant url --
cy.wait('@firstCall') // Success!
cy.route(new RegExp('/mysite.com/entitiesCollection.*page[offset]=20.*'), response2).as('secondCall');
// something happens here that triggers the call to the relevant url with page[offset]=20--
cy.wait('@secondCall') // Success
cy.route(new RegExp('/mysite.com/entitiesCollection.*page\[offset\]=20\&page\[limit\]=100.*'), response3).as('thirdCall');
// something happens here that triggers the call to the url + page[offset]=20&page[limit]=100 query params
cy.wait('@thirdCall') // Success |
Yes, it does appear that routes that match RegExp would have precedence over routes that match by string. https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cypress/server.coffee#L266 |
Thanks a lot for this hint! While actually waiting for #387 I'm going to try changing my route urls to Regex now. Hope that works. |
* cypress.json - generally set requestTimeout=30secs (see comment) * sales_order_spec.js - specifically wait for the POST to quickInput (that finally resets the quickinput fields) * we have a bunch of less specific aliases in this test and don't want to accidentally match any of those * form.js and general.js - change route url globs to regexes, because hopefully that way the newest route is matched as the preferred one; see cypress-io/cypress#3248 (comment) https://github.com/metasfresh/metasfresh-e2e/issues/
Unfortunately this didn't work out either.. |
Is there any solution to support multi cy.route for same request url? |
Going to merge this issue into this duplicate issue with a reproducible example. #4460 |
Hi All, I still see this issue in the latest version of Cypress v4.11.0, its now Aug 2020, has this been solved? |
@front-end-developer Please see this issue: #4460 |
Current behavior:
When having multiple routes with paths that match a request, the newest one assigned does not match and a different stub is used.
E.g - (with the following endpoint:
mysite.com/entitiesCollection
)Desired behavior:
When matching routes, newer should take precedence over older.
Steps to reproduce: (app code and test code)
See the example above
Versions
cypress 3.1.4, OSX Mojave, Chrome 71
The text was updated successfully, but these errors were encountered: