I hope you're doing well. I'm currently working on the upgrade of cypress to 7.0. (v7.4.0 more exactly) I have an issue with the overriding of intercept calls.
It seems that Cypress team worked on the overriding problem https://github.com/cypress-io/cypress/pull/14543 (issue : https://github.com/cypress-io/cypress/issues/9302), but it doesn't work for me.
BREAKING CHANGE: Request handlers supplied to cy.intercept are now matched starting with the most-recently-defined request interceptor. This allows users to override request handlers by calling cy.intercept again. This matches the previous behavior that was standard in cy.route.
My first call deals with 2xx responses (I mock it myself)
cy.intercept('GET', 'sameUrl', {
statusCode: 2xx
}
but then I need another intercept with the same url but a different status :
cy.intercept('GET', 'sameUrl', {
statusCode: 4xx
}
I tried using middleware
:
A new option, middleware, has been added to the RouteMatcher type. If true, the supplied request handler will be called before any non-middleware request handlers.
cy.intercept({ method: 'GET', url: 'sameUrl', middleware: true}, req => {
req.continue(res => {
res.statusCode = 4xx
});
}
But it didn't work, the first intercept is always the one being called. Please if you have any idea what I did wrong/another solution I'm all ears !