Skip to content
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

Unexpected error when stubbing a request with cy.intercept(string, { headers: {} }) #16117

Closed
flotwig opened this issue Apr 21, 2021 · 2 comments · Fixed by #16167
Closed

Unexpected error when stubbing a request with cy.intercept(string, { headers: {} }) #16117

flotwig opened this issue Apr 21, 2021 · 2 comments · Fixed by #16167
Labels
topic: cy.intercept() type: regression A bug that didn't appear until a specific Cy version release v7.0.0 🐛 Issue present since 7.0.0

Comments

@flotwig
Copy link
Contributor

flotwig commented Apr 21, 2021

Current behavior

In Cypress 7, the cy.intercept(url, routeMatcher) overload was added. Now, when doing the following:

cy.intercept('/url', { headers: { foo: 'bar' }, body: '' })

or a variation, you get the following error:

When invoking cy.intercept() with a RouteMatcher as the second parameter, a handler (function or StaticResponse) must be specified as the third parameter. If you intended to stub out a response body by passing an object as the 2nd parameter, pass an object with a body property containing the desired response body instead.

image

Obviously this is not quite the case, since the object DOES have a body property.

Desired behavior

2nd argument is treated as StaticResponse in this case

This check: if (_.isString(matcher) && hasRouteMatcherKeys(handler)) { should probably do hasONLYRouteMatcherKeys(handler) to avoid this problem.

Test code to reproduce

Versions

Cypress 7.0.0

@flotwig flotwig added type: regression A bug that didn't appear until a specific Cy version release topic: cy.intercept() v7.0.0 🐛 Issue present since 7.0.0 labels Apr 21, 2021
flotwig added a commit that referenced this issue Apr 23, 2021
@cypress-bot cypress-bot bot added stage: work in progress stage: needs review The PR code is done & tested, needs review and removed stage: work in progress labels Apr 23, 2021
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Apr 26, 2021

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

@cypress-bot cypress-bot bot removed the stage: needs review The PR code is done & tested, needs review label Apr 26, 2021
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Apr 26, 2021

Released in 7.2.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v7.2.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Apr 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
topic: cy.intercept() type: regression A bug that didn't appear until a specific Cy version release v7.0.0 🐛 Issue present since 7.0.0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant