question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cy.intercept should provide req.query since the url has the query object

See original GitHub issue

Current behavior

req.url looks like http://hostname:port/?someKey=someValue but req.query is undefined.

Desired behavior

req.url looks like http://hostname:port/?someKey=someValue and req.query is { someKey: 'someValue' }.

Test code to reproduce

cy.intercept({ hostname }, (req) => {
  console.log(req.query) // undefined
  console.log(req.url) // http://hostname:port/?someKey=someValue
})

Versions

Cypress: 7.2.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
cypress-bot[bot]commented, Jun 23, 2021

The code for this is done in cypress-io/cypress#16916, but has yet to be released. We’ll update this issue and reference the changelog when it’s released.

1reaction
flotwigcommented, May 5, 2021

Yeah, I agree that it’s weird to not have query. The only problem with this proposal is that req.url contains the querystring and can be modified, so it stands to reason that req.query can be modified as well. So, if a query property was added, any changes the user makes to it would have to be reconciled with changes to req.url somehow.

IMO the best way to implement this would be to add req.query, but make it just a fancy getter/setter for req.url, so the two can never be out of sync. What do you two think?

Read more comments on GitHub >

github_iconTop Results From Across the Web

intercept - Cypress Documentation
The routeHandler function is called whenever a request is matched, with the first argument being the request object. From inside the callback, you...
Read more >
cypress - cy.intercept() for post endpoints with query parameters
I tried the same thing for a post endpoint that requires a query params in the URL but it didn't work. In the...
Read more >
A Practical Guide to Intercepting Network Requests in Cypress
Our .intercept() command is now matching any request that contains the url /api/boards . You can see this in a screenshot below.
Read more >
Cypress cy.intercept Problems - Gleb Bahmutov
The command cy.intercept can match requests using a substring, a minimatch, or a regular expression. By default, it intercepts requests matching ...
Read more >
Cypress - intercept Spy and stub network requests responses.
cy.intercept() is the successor to cy.route() as of Cypress 6.0.0. ... you have access to the entire request-response where you can modify the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found