-
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
intercept leaks between tests #27309
Comments
Hey there, I'm a bit late but I noticed you're having a bit of trouble with your Cypress tests, where intercepts seem to be causing issues between different test cases. Not to worry, this is a common challenge that we can easily tackle. You mentioned that you're using a To ensure that each test case runs independently without interference, let's make a small adjustment. Instead of setting up the intercepts in a shared Here's how you can do it: describe("test", () => {
it("will work", (done) => {
// Set up the intercept for this specific test
cy.intercept({
method: "GET",
url: "**/path",
}, {
statusCode: 200,
body: { a: 1 },
headers: {
"content-type": "application/json"
}
}).as("call");
// Perform your fetch and assertions
fetch("http://localhost:400/root/path").then(response => {
response.json().then(json => {
expect(json).to.deep.equal({a: 1});
done();
})
});
// Wait for the intercept to complete
cy.wait("@call");
});
// Repeat the same pattern for other test cases
// ...
}); By placing the I hope this helps you achieve the desired behavior in your Cypress tests. Don't hesitate to reach out if you have any more questions or need further assistance. Happy testing!**** |
Hi @DevJSter, I have already placed the intercepts in each tests. Please, have a closer look to the |
Alright sir 😄 |
Any updates about this issue? |
@Renkoru, I manage to fix the issue by making the tests async by moving them in it("will work 2", done => {
cy.intercept({
method: "GET",
url: "**/path",
}, {
statusCode: 300,
body: { message: "the-message" },
headers: {
"content-type": "application/json"
}
}).then(() => {
fetch("http://localhost:400/root/path").then(response => {
response.json().then(json =>{
expect(json).to.deep.equal({ message: "the-message" });
done();
})
});
});
}); |
Thank you @hamidmayeli for your reply. I have fixed my issue with disabling cache:
|
This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided. |
This issue has been closed due to inactivity. |
Current behavior
When you have multiple tests reaching out to the same path, intercepts leak between tests.
There are a few close related to same thing and they suggest it should be fixed in V6.
Desired behavior
Tests be independent.
Test code to reproduce
Cypress Version
^12.17.1
Node version
v20.3.1
Operating System
Windows 10 x64 Version 10.0.19045 Build 19045
Debug Logs
I couldn't add the logs as it was too long.
Other
The text was updated successfully, but these errors were encountered: