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
intercept()'s minimatch glob-matching against routeMatcher url property no longer works #9379
Comments
I saw this, but I'm not sure if dropping minimatch support was intentional: |
@knotthere |
@flotwig - Thank you for the followup and confirmation minimatch should still be supported. I will circle back on my code and provide a repeatable example (if this was not simply user-error on my part.) |
Ok, I added example in https://github.com/bahmutov/cy-intercept-example - it can be tricky if the URL has query parameters. // to match "https://jsonplaceholder.cypress.io/users?_limit=3"
cy.intercept('**/users?*').as('users')
cy.get('#load-users').click()
cy.wait('@users') Had to do a few tries in the DevTools console like this until found Cypress.minimatch('https://jsonplaceholder.cypress.io/users?_limit=3', '**/users', {debug: true}) |
Seems to be a duplicate of #9305 |
I am struggling with the same issue, the minimatch pattern does not work for intercept:
|
@Pirlouit - Yes, I began converting my |
Hey @knotthere, |
I think this is related/a dupe to #9340 |
Reproducible Example// ✅ passes
it('cy.route() passes', () => {
cy.server()
cy.route('/users/search*').as('getUrl')
cy.visit('https://example.com')
cy.window().then((win) => {
const xhr = new win.XMLHttpRequest()
xhr.open('GET', '/users/search?=Sarah')
xhr.send()
})
cy.wait('@getUrl')
})
// ❗️ fails
it('cy.intercept() fails', () => {
cy.intercept('/users/search*').as('getUrl')
cy.visit('https://example.com')
cy.window().then((win) => {
const xhr = new win.XMLHttpRequest()
xhr.open('GET', '/users/search?=Sarah')
xhr.send()
})
cy.wait('@getUrl')
})
// ✅ passes
it('cy.intercept() with pathname passes', () => {
cy.intercept({
method: 'GET',
pathname: '/users/search*'
}).as('getUrl')
cy.visit('https://example.com')
cy.window().then((win) => {
const xhr = new win.XMLHttpRequest()
xhr.open('GET', '/users/search?=Sarah')
xhr.send()
})
cy.wait('@getUrl')
}) |
The main issue here seems to be that
// ✅ matches http://example.com/foo/1
cy.route('http://example.com/foo/*')
// ✅ matches http://example.com/foo/1
cy.route('/foo/*') As of 6.1.0, // ❌ does not match http://example.com/foo/1
cy.intercept('/foo/*')
// ✅ matches http://example.com/foo/1
cy.intercept({ pathname: '/foo/*' })
// ✅ matches http://example.com/foo/1
cy.intercept('http://example.com/foo/*')
// ✅ matches http://example.com/foo/1
cy.intercept('**/foo/*') Potentially, // could be updated to match against pathname or full URL, like cy.route
cy.intercept('/foo/*')
// would still only match against full URL
cy.intercept({ url: 'http://example.com/foo/*' })
// would still only match against pathname
cy.intercept({ pathname: '/foo/*' }) |
We are planning to update cy.intercept() to match the old behavior like cy.route() matching as Zach showed above. |
The code for this is done in cypress-io/cypress#14241, but has yet to be released. |
Thank you for addressing this. I await a new release so I can complete my port to Cypress 6.x. |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Current behavior
In Cypress 4.12.1, matching a route (
cy.route()
) with aurl
property that contains a string with minimatch syntax (*
) works.In Cypress 6.0.0, using
cy.intercept()
with arouteMatcher.url
that also contains minimatch syntax fails to match.The help at https://docs.cypress.io/api/commands/intercept.html#routeMatcher-RouteMatcher says:
Desired behavior
Glob-matching should succeed with string properties passed to
cy.intercept()
in arouteMatcher
.Test code to reproduce
Versions
The text was updated successfully, but these errors were encountered: