4

I have an intercept that serves up a stubbed json response like this:

    cy.intercept('GET', '**/api/v1/myroute/*', { fixture: 'myData.json' }).as('myAlias')

Is there a way I can remove this intercept halfway through a test somehow? I was hoping to delete the alias so the xhr request doesn't get intercepted at all. Thanks!

Ben Power
  • 1,786
  • 5
  • 27
  • 35

2 Answers2

2

OK, figured this one out. Simply do this:

cy.intercept('GET', '**/api/v1/myroute/*', (req) => {
  req.continue()
});
Ben Power
  • 1,786
  • 5
  • 27
  • 35
  • How did you implement it? It does not change the result for me: `cy.intercept('/api/console/profile', (req) => { req.continue((res) => { res.send({ result: updatedPhoneNumberProfile, }); }); })` – SalahAdDin Nov 02 '22 at 17:31
1

You can try to use RouteMatcher's times option like this:

cy.intercept({
  method: 'GET',
  pathname: '/api/v1/myroute/*'
  times: 1
}, { fixture: 'myData.json' }).as('myAlias')

so when it is called a second time it won't be intercepted

sunsay
  • 1,500
  • 2
  • 21
  • 28