-
Notifications
You must be signed in to change notification settings - Fork 3.3k
cannot overwrite cy.route command #3890
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
Comments
Quickly check: Could you try to write the route as '/comments/*' instead of 'comments/*' ? |
@bahmutov have you made any progress on this? I'd like to create a route based on the request body (in addition to the method and url). |
@bahmutov do you have any updates on this? We also ran into it. Thanks! |
We also have this issue. Once route is defined - it persist the first version of the mock. Makes it harder to check negative cases. |
Give this a try. Using "as" with this new route command works as well. Cypress.Commands.overwrite('route', (route, ...args) => {
return cy.log(`cy.route ${args.join(' ')}`).then(() => {
return route(...args);
})
}); |
We had an use case where we had to overwrite route and this is the only we could make it work: Cypress.Commands.overwrite('route', (originalFn, ...args) => {
if (args[2]) {
if (args[2].csrfToken) {
originalFn({
method: args[0],
url: args[1],
onRequest: xhr => {
xhr.setRequestHeader('X-CSRF-Token', 'true');
},
});
}
} else {
originalFn(...args);
}
}); In the documentation it shows that we need to return the original function. But when I returned it, it never works. Also my another question is, can I overwrite cy.server()? |
The code for this is done in cypress-io/cypress#9613, but has yet to be released. |
The code for this is done in cypress-io/cypress#14202, but has yet to be released. |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Cypress 3.2.0
Aliases test in cypress-example-kitchensink. I am trying to overwrite
cy.route
command to display the route to be spied on.Gives me an error message
If I return undefined, then alias
as
seems to not work - even as it is shown in the list of registered aliasescypress run
outputThe text was updated successfully, but these errors were encountered: