Skip to content

[7.0.0] cy.intercept(): stubbed responses still send request to server #15841

@risa-hdqc

Description

@risa-hdqc

Current behavior

After upgrading from 6.7.1 to 7.0.0, I noticed my tests are still working as expected, but my server logs show requests being made to my server for intercepted requests using fixtures, objects, or strings.

    cy.intercept('/api/getThings', { fixture: 'getThings' });
    cy.intercept('/api/getAnotherThing', 'AnotherThing');
    cy.intercept('/api/getYetAnotherThing', { text: 'YetAnotherThing' });

Each of these intercepts will return the stubbed response, but the requests are still being made afterward.

Example server log:

GET /api/getThings 200 4.389 ms - -
error: GET - 500 - /api/getThings -- some error because I'm not using a live service
GET /api/getAnotherThing 200 2.312 ms - -
error: GET - 500 - /api/getThings -- some error because I'm not using a live service
GET /api/getYetAnotherThing 200 4.231 ms - -
error: GET - 500 - /api/getYetAnotherThing -- some error because I'm not using a live service

Desired behavior

The requests should NOT go to the server after returning the stubbed response.

GET /api/getThings 200 4.389 ms - -
GET /api/getAnotherThing 200 2.312 ms --
GET /api/getYetAnotherThing 200 4.231 ms --

Current workaround

req.reply works as expected, blocking the requests to the server.

    cy.intercept('/api/getThings', (req) => req.reply({ fixture: 'getThings' }));
    cy.intercept('/api/getAnotherThing', (req) => req.reply('AnotherThing'));
    cy.intercept('/api/getYetAnotherThing', (req) => req.reply({ text: 'YetAnotherThing' }));

Versions

7.0.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