cypress: Fail to intercept same URL requests in different testing function
Current behavior
I would like to use the API call with the URL ‘/api/apps*’.
There are three tests within a single describe function.
Each test will use cy.intercept to intercept the same API, but perform different actions.
When I run all three tests together, only the first interception passes.
However, if I test the second interception individually, it works.
Desired behavior
should be passed in three testing if intercept the same url.
Test code to reproduce
describe('Apps', () => {
const apiURL = '/api/apps*';
it('First testing', () => {
cy.intercept('GET', apiURL, (req) => { ... }).as('getFirst');
// success
cy.wait('@getFirst');
})
it('Second testing', () => {
cy.intercept('GET', apiURL, (req) => { ... }).as('getSecond');
//fail: timeout
cy.wait('@getSecond');
})
it('Third testing', () => {
cy.intercept('GET', apiURL, (req) => { ... }).as('getThird');
//fail: timeout
cy.wait('@getThird');
})
})
Cypress Version
12.8.1
Node version
v18.14.1
Operating System
macOS 13.2.1(22D68)
Debug Logs
No response
Other
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 18 (5 by maintainers)
We are having the same problem, but only in Electron. Also, we have the intercept in
beforeEach. In our case too, the request doesn’t occur so the route matcher doesn’t have what to match. When I use Chrome, it works fine.We are using Amplify and we need to run the Cypress tests during Amplify build, so we really need the tests to run on Electron.
Similar issue (closed): #26120
Hi Jordan, I think I am doing E2E testing, try to simulate different scenarios (404 Error or no match API schema …) and expect APP can render right content or route to correct page.