cannot overwrite cy.route command
See original GitHub issueCypress 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.
Cypress.Commands.overwrite('route', (route, ...args) => {
cy.log('foo').then(() => {
return route(...args)
})
})
it('.as() - alias a route for later use', () => {
cy.visit('https://example.cypress.io/commands/aliasing')
cy.server()
cy.route('GET', 'comments/*').as('getComment')
cy.get('.network-btn').click()
cy.wait('@getComment').its('status').should('eq', 200)
})
Gives me an error message
1) Aliasing .as() - alias a route for later use:
CypressError: Cypress detected that you invoked one or more cy commands in a custom command but returned a different value.
The custom command was:
> cy.server()
The return value was:
> Object{24}
Because cy commands are asynchronous and are queued to be run later, it doesn't make sense to return anything else.
For convenience, you can also simply omit any return value or return 'undefined' and Cypress will not error.
In previous versions of Cypress we automatically detected this and forced the cy commands to be returned. To make things less magical and clearer, we are now throwing an error.
If I return undefined, then alias as
seems to not work - even as it is shown in the list of registered aliases
Cypress.Commands.overwrite('route', (route, ...args) => {
cy.log(`cy.route ${args.join(' ')}`)
route(...args)
})
cypress run
output
1) .as() - alias a route for later use
visit http://localhost:8080/commands/aliasing
log cy.server
log cy.route GET comments/*
get .network-btn
click
xhr GET https://jsonplaceholder.cypress.io/comments/1
log [getComment]
wait @getComment
1 passing (5s)
1 failing
1) Aliasing .as() - alias a route for later use:
CypressError: cy.wait() only accepts aliases for routes.
The alias: 'getComment' did not match a route.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:10 (1 by maintainers)
Top Results From Across the Web
Overwriting an existing command with Cypress - Stack Overflow
I'm trying to overwrite an existing command in Cypress.io. I'm looking to log() a route response's status & the route's url to extend...
Read more >Cypress cy.intercept Problems - Gleb Bahmutov
You can overwrite Cypress commands and log a message to the Command Log. Unfortunately overwriting cy.intercept has a bug with aliases #9580 ...
Read more >Migrating .route() to .intercept() in Cypress - Filip Hric
I have written a blog about this(it was available as an experimental feature). You can judge by the name, that there was clearly...
Read more >intercept - Cypress Documentation
cy.intercept can be used solely for spying: to passively listen for matching routes and apply aliases to them without manipulating the request or...
Read more >Cypress v6: Network control using cy.intercept introduction
In this video, I will give a glimpse of cy.intercept command (see ... a much more powerful replacement for the deprecated cy. route...
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
We also have this issue. Once route is defined - it persist the first version of the mock. Makes it harder to check negative cases.
@bahmutov do you have any updates on this? We also ran into it.
Thanks!