Reset intercepted requests #17051
-
Hey y'all, Is there a way to reset an intercepted request? export const setupWithMocks = () => {
// mock common routes
cy.intercept('/foo', { fixture: 'foo.json' });
cy.intercept('/bar', { fixture: 'bar.json' });
cy.intercept('/baz', { fixture: 'baz.json' });
// reset / set localStorage
window.localStorage.removeItem(`userConfig`);
window.localStorage.setItem('foo', ['bar']);
// ... and some more
}; This work perfectly for lots of tests: describe(`...`, () => {
beforeEach(() => {
setupWithMocks();
});
// ...
}); But now I want to NOT intercept one of the requests just for a single test case: describe(`...`, () => {
beforeEach(() => {
setupWithMocks();
});
it('should display the map view', () => {
// ??? how can I reset / remove the interception for e.g. cy.intercept('/foo', { fixture: 'foo.json' });
});
// ...
}); How can I do this? Any ideas? Is this maybe a missing feature? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
The way to do this is to define a more specific cy.intercept('/foo', (req) => {
// override the previously-declared stub to just continue the request instead of stubbing
req.continue()
}) |
Beta Was this translation helpful? Give feedback.
The way to do this is to define a more specific
cy.intercept()
override that continues the response without stubbing it. Since non-middleware
cy.intercept()
s are matched from newest to oldest, this will work: