-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
XHR requests are not stubbed with intercept
when server isn't running
#9599
Comments
Can you give intercepts aliases so you can see which ones are actually intercepted?
…Sent from my iPhone
On Dec 9, 2020, at 14:47, Maxime Dupré ***@***.***> wrote:
Current behavior
I posted this problem on gitter and another user ***@***.***_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:
And here's what happens when I simply turn on my API and re-run the tests:
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
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
could you screenshot when the API is off? |
Hmm, in cypress-io/cypress-example-recipes#606 I am stubbing the second API endpoint that does not exist, but it works fine. Are your requests going to the right port? I see a mixture of 4200 and 3030. Is this app public or could you create a public reproduction? |
Requests are going to the right ports. API is at http://localhost:3030 and front-end is at https://localhost:4200. Unfortunately this isn't a public app and I don't have the time right now to do a repro. I just tried "http://localhost:4200" (instead of https, to make both the api and front end http), but same problem. |
This looks very similar to the issue that I just posted: #9602 |
Having the same issue here with |
We believe this problem is related to the OPTIONS call that happens before the actual call cross domain
…Sent from my iPhone
On Dec 9, 2020, at 21:52, Kunal Nagar ***@***.***> wrote:
Hey guys - do you think the problem may be related to pattern matching of the URL on cy.intercept? In my particular scenario, if I use:
// WORKS
cy.server()
cy.route('**/v1/answers**', 'fixture:answers.json')
// DOES NOT WORK
cy.intercept('GET', '**/v1/answers**', { fixture: 'answers.json' })
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
I have the same problem. My |
I've spotted a failed OPTIONS request as well after the GET |
The code for this is done in cypress-io/cypress#9631, but has yet to be released. |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
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:
And here's what happens when I simply turn on my API and re-run the tests:
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
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
The text was updated successfully, but these errors were encountered: