Skip to content

XHR requests are not stubbed with intercept when server isn't running #9599

@maximedupre

Description

@maximedupre

Current behavior

I posted this problem on gitter and another user (@genughaben_gitlab) confirmed he also has this problem.

I want to stub my local REST API to test my front end in insolation. When the REST API is turned on, everything works as expected - the XHR are stubbed. When my REST API is turned off, the XHR fail and are not stubbed.

For example, here's what happens when my API is not started:

Screen Shot 2020-12-09 at 2 20 12 PM
Screen Shot 2020-12-09 at 2 25 51 PM
Screen Shot 2020-12-09 at 2 26 29 PM

And here's what happens when I simply turn on my API and re-run the tests:

Screen Shot 2020-12-09 at 2 23 53 PM

Desired behavior

My server should not be started for XHR stubs to work

Test code to reproduce

Unable to provide a repro, but here is test code for the test shown in the screenshot

describe('Project page', () => {
    beforeEach(() => {
        helper.login(1);
    });

    describe('when the play button is clicked', () => {
        describe('when the stop button is clicked', () => {
            it.only('should stop the project', () => {
                defaultIntercepts();
                cy.visit('https://localhost:4200/projects/1');

                cy.get('#play-button').click();
                cy.get('#stop-button').click();

                const playheadLeftPosObj = { pos: 0 };

                setInitialPlayheadLeftPos(playheadLeftPosObj);
                cy.get('#playhead').should(($el: any) => {
                    expect($el[0].getBoundingClientRect().left).to.equal(
                        playheadLeftPosObj.pos
                    );
                });
            });
        });
    });
});

function defaultIntercepts() {
    cy.intercept('GET', '/users/1', {
        id: 1
    });
    cy.intercept(
        'GET',
        '/projects/1?used-space-wavs-and-videos',
        createProjectFixtures({})
    );
    cy.intercept('GET', '/projects/1/tracks', []);
    cy.intercept('GET', '/projects/1/files?is-consolidation', []);
}

Versions

This issue did not occur with cy.route.

Cypress version: 6.1
Chrome version: Version 87.0.4280.67 (Official Build) (x86_64)
OS version: mac os 10.15.7

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions