-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Description
Current behavior
I have a react component containing the code:
const response = await fetch('.data/me');
My component tests has the intercept:
it('shows name after successful fetch', () => {
cy.intercept('GET', '**/.data/me', {
statusCode: 200,
body: { name: 'John' }
}).as('getData1')
cy.mount(<App />)
cy.contains('Hello, John').should('be.visible')
})
But the test failing in UI with the "Timed out retrying after 4000ms: Expected to find content: 'Hello, John' but never did." error, because Cypress failed to mock the request.
According to DevTools, it was successfully passed to http://localhost:5173/__cypress/iframes/.data/me
and response contains some cypress internal code.
Desired behavior
I'd expect that fetches without leading slash should be mocked. I understand that it's a bad pattern, but some apps use it, and it may be impossible to change this logic on the app side.
Test code to reproduce
I created a project to reproduce the issue: https://github.com/DeniDoman/vite-react-starter
Component code: https://github.com/DeniDoman/vite-react-starter/blob/main/src/App.tsx
Test code: https://github.com/DeniDoman/vite-react-starter/blob/main/src/App.cy.tsx
Cypress Version
14.1.0
Node version
v18.19.1
Operating System
macOS 14.5 (23F79)