Skip to content
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

Cypress can't intercept fetch requests with no leading slash #31215

Open
DeniDoman opened this issue Mar 4, 2025 · 0 comments
Open

Cypress can't intercept fetch requests with no leading slash #31215

DeniDoman opened this issue Mar 4, 2025 · 0 comments
Labels
stage: needs investigating Someone from Cypress needs to look at this

Comments

@DeniDoman
Copy link

DeniDoman commented Mar 4, 2025

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)

@jennifer-shehane jennifer-shehane added the stage: needs investigating Someone from Cypress needs to look at this label Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage: needs investigating Someone from Cypress needs to look at this
Projects
None yet
Development

No branches or pull requests

2 participants