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

Intercept i is not showing the latest respnose if Intercept same call multiple times #20697

Closed
varshanharshank opened this issue Mar 18, 2022 · 5 comments
Labels
stale no activity on this issue for a long period

Comments

@varshanharshank
Copy link

varshanharshank commented Mar 18, 2022

Current behavior

During end to end testing, I am intercepting the same api call many places (each place, it will provide different response). When i use cy.wait() command to retrieve the response, it is always showing the old response (it means, it is showing response which intercepted first time)

    cy.intercept('**customerInfo/inventory/review/*').as('reviewInvetory')
    cy.wait('@reviewInvetory').then((res) => {
      cy.log(JSON.stringify(res.response?.body))
    }) //printing reviewInvetory1 response
    //doing some action in the application, then again intercepting the same call
    cy.intercept('**customerInfo/inventory/review/*').as('reviewInvetory')
    cy.wait('@reviewInvetory').then((res) => {
      cy.log(JSON.stringify(res.response?.body))
    }) //printing the first call data instead of printing the latest intercept call

Desired behavior

Expecting to show latest call instead of showing the old call

Test code to reproduce

I can't share my repo to public

Cypress Version

9.4

Other

No response

@emilyrohrbough
Copy link
Member

@varshanharshank Can you provide a reproducible example using https://github.com/cypress-io/cypress-test-tiny since you are unable to share you're repo? I tired to reproduce the issue and was unable to. Here is the test I used:

it('test intercept response that is used when called multiple times', () => {
  cy.intercept('https://jsonplaceholder.cypress.io/*', {
    statusCode: 200,
    headers: {
      'content-type': 'text/html',
    },
    body: 'response1'
  }).as('request')

  cy.visit('https://jsonplaceholder.cypress.io/comments')

  cy.wait('@request').then(({ response }) => {
    expect('response1').to.eq(response.body)
  })

  cy.intercept('https://jsonplaceholder.cypress.io/*', {
    statusCode: 200,
    headers: {
      'content-type': 'text/html',
    },
    body: 'response2'
  }).as('request')

  cy.visit('https://jsonplaceholder.cypress.io/comments')

  cy.wait('@request').then(({ response }) => {
    expect('response2').to.eq(response.body)
  })
})

@restrin-extensis
Copy link

I ran into the same issue (I'm on 9.7.) I discovered using server().route() rather than intercept() worked around the problem.

@Deop
Copy link

Deop commented Mar 30, 2023

I've been having this issue ever since switching to using cy.intercept instead of cy.route. It's a bit hard to find reproducible example without giving access my project. But issue is usually happen when you stay on the same page and do the same request (for example do search with the same text twice). It usually just match wait for to the first route it already matched and give you response of that first route.

@cypress-app-bot
Copy link
Collaborator

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label Sep 27, 2023
@cypress-app-bot
Copy link
Collaborator

This issue has been closed due to inactivity.

@cypress-app-bot cypress-app-bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale no activity on this issue for a long period
Projects
None yet
Development

No branches or pull requests

5 participants