Skip to content

Unable to save fixture from response provided in route2 #9190

Closed
@mzedeler

Description

@mzedeler

The route2 reply handler doesn't allow any further commands, making it impossible to save fixtures, which is necessary for us to be able to use Cypress for mocking our backend.

Using the following example:

    cy.route2(matcher, request => request.reply(response => {
        const obj = {
          url: request.url,
          request: _pick(request, ['method', 'body']),
          response: _pick(response, ['body', 'headers', 'statusCode'])
        }
        cy.writeFile(
          path.join('cypress', 'fixtures', fixturePath, 'mock.json'),
          obj
        )
      })
    )

Current behavior

Using the snippet above causes this error:

Uncaught CypressError: The following error originated from your test code, not from Cypress.

  > A response callback passed to `req.reply()` threw an error while intercepting a response:

Cypress detected that you returned a promise from a command while also invoking one or more cy commands in that promise.

The command that returned the promise was:

  > `cy.visit()`

The cy command you invoked inside the promise was:

  > `cy.writeFile()`

Desired behavior

Make it possible to access the response outside route2, possibly by letting the handler inside reply yield it.

Test code to reproduce

See the snippet above.

Versions

5.6.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions