-
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
cy.intercept should provide req.query since the url has the query object #16327
Comments
I can recreate this. Although I don't see But I can see the usefulness of wanting the req.query here. Exampleit('test cy.intercept()', () => {
cy.intercept({ url: '/users' }, (req) => {
console.log(req)
console.log(req.query) // undefined
console.log(req.url) // https://example.com/users?someKey=someValue
}).as('getUrl')
cy.visit('https://example.com')
cy.window().then((win) => {
const xhr = new win.XMLHttpRequest()
xhr.open('GET', '/users?someKey=someValue')
xhr.send()
})
cy.wait('@getUrl')
}) |
You are right, I think based on there being a query matcher I thought there would also be a query in the response, so this is more of a feature request. I was trying to do something like this for GraphQL: cy.intercept({ hostname }, (req) => {
if (req.query?.operationName) {
req.alias = req.query.operationName
} else if (req.body?.query && req.body?.operationName) {
req.alias = req.body.operationName
} but ended up doing this for now: cy.intercept({ hostname }, (req) => {
if (req.url.includes('operationName')) {
const { search } = url.parse(req.url)
const searchParams = new URLSearchParams(search)
req.alias = searchParams.get('operationName')
} else if (req.body?.query && req.body?.operationName) {
req.alias = req.body.operationName
} since we use persisted queries and this aliases the request based on GET vs POST and query vs mutation (which are not persisted). |
Yeah, I agree that it's weird to not have IMO the best way to implement this would be to add |
That sounds good to me! |
The code for this is done in cypress-io/cypress#16916, but has yet to be released. |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Current behavior
req.url
looks likehttp://hostname:port/?someKey=someValue
butreq.query
isundefined
.Desired behavior
req.url
looks likehttp://hostname:port/?someKey=someValue
andreq.query
is{ someKey: 'someValue' }
.Test code to reproduce
Versions
Cypress: 7.2.0
The text was updated successfully, but these errors were encountered: