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

Static replies in Intercept drop falsy values #15234

Closed
jeremydorne opened this issue Feb 25, 2021 · 2 comments · Fixed by #15235
Closed

Static replies in Intercept drop falsy values #15234

jeremydorne opened this issue Feb 25, 2021 · 2 comments · Fixed by #15235

Comments

@jeremydorne
Copy link
Contributor

jeremydorne commented Feb 25, 2021

Current behavior

Currently, if a falsy, but not undefined, value is passed as a static response such as req.reply({ body: false }), the boolean value is dropped by the net-stubbing backend. This behavior does not match up with the behavior for true, where req.reply({ body: true }) will return true.

Desired behavior

At the very least, there should be consistency in how net-stubbing handles boolean values. I see two reasonable options:

  1. Return falsy static responses. This would provide consistent behavior with truthy values of the same type.
  2. Throw a runtime error when non object or string values are used as static responses. Currently, when falsy values are dropped, a response is returned without any indication that something went wrong.

I think the first option is the preferable one, and while the type definition for static responses only includes strings and JSON objects, I expect others might also be implicitly relying on req.reply to handle other types like booleans or numbers.

I have a branch that adds a couple undefined checks in place of truthy checks that would match fix #1.

Test code to reproduce

This is a test case that describes the current behavior.

Versions

Cypress 6.x

@jeremydorne jeremydorne changed the title Static replies in Intercept drop falsy values. Static replies in Intercept drop falsy values Feb 25, 2021
@cypress-bot cypress-bot bot added the stage: work in progress There is an open PR for this issue [WIP] label Feb 25, 2021
@jeremydorne jeremydorne changed the title Static replies in Intercept drop falsy values fix(net-stubbing): Static replies in Intercept drop falsy values Feb 25, 2021
@jeremydorne jeremydorne changed the title fix(net-stubbing): Static replies in Intercept drop falsy values Static replies in Intercept drop falsy values Feb 25, 2021
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Mar 10, 2021

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

@cypress-bot cypress-bot bot added stage: pending release There is a closed PR for this issue and removed stage: work in progress There is an open PR for this issue [WIP] labels Mar 10, 2021
@flotwig flotwig closed this as completed Mar 16, 2021
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Apr 5, 2021

Released in 7.0.0.

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

@cypress-bot cypress-bot bot removed the stage: pending release There is a closed PR for this issue label Apr 5, 2021
@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Apr 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants