Skip to content

Static replies in Intercept drop falsy values #15234

Closed
@jeremydorne

Description

@jeremydorne

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions