Skip to content

feat: cy.intercept provides req.query. #16916

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

Merged
merged 9 commits into from
Jun 23, 2021
Merged

Conversation

sainthkh
Copy link
Contributor

@sainthkh sainthkh commented Jun 14, 2021

User facing changelog

The incoming request object yielded to request handler functions passed to cy.intercept() (req) now has a req.query property, which is a getter/setter for the query parameters on the request URL.

Additional details

  • Why was this change necessary? => When there's query on url, it's convenient to have parsed query string.
  • What is affected by this change? => N/A
  • Any implementation details to explain? => I added query, url getter and setter to req object.

How has the user experience changed?

Before: req.query => undefined.
After: req.query => { a: 'b' }

PR Tasks

Sorry, something went wrong.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jun 14, 2021

Thanks for taking the time to open a PR!

@sainthkh
Copy link
Contributor Author

Flaky failures.

@sainthkh sainthkh marked this pull request as ready for review June 14, 2021 03:06
@sainthkh sainthkh requested a review from a team as a code owner June 14, 2021 03:06
@sainthkh sainthkh requested review from flotwig and chrisbreiding and removed request for a team June 14, 2021 03:06
Copy link
Contributor

@flotwig flotwig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice work. LGTM once the docs PR is ready

Comment on lines +1704 to +1747
cy.window().then((win) => {
const xhr = new win.XMLHttpRequest()

xhr.open('GET', '/users?someKey=someValue')
xhr.send()
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no need to do this btw, $.get is available in this context and doesn't require scoping into cy.window().then()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$.get appends its own query member like _=12345 behind the scene. Because of that, we cannot use them for our tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can pass cache: true to not do that

Copy link
Contributor Author

@sainthkh sainthkh Jun 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't work with Firefox. I rolled it back.

sainthkh and others added 8 commits June 22, 2021 10:56
fix

Verified

This commit was signed with the committer’s verified signature.
bhrutledge Brian Rutledge

Verified

This commit was signed with the committer’s verified signature.
bhrutledge Brian Rutledge

Verified

This commit was signed with the committer’s verified signature.
bhrutledge Brian Rutledge
@cowboy cowboy requested a review from mccataldo June 22, 2021 14:11
@cowboy
Copy link
Contributor

cowboy commented Jun 22, 2021

Adding @mccataldo to review from a DX perspective

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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