https://cypress.io logo
Intercept 2 network calls at the same time
# i-need-help
s
I got a button that when I click on, it sends 2 network calls with the same endpoint, and when I intercept 1 of them, it detects both of them, but I need only the 2nd call, how can I intercept only the 2nd call?
n
you could wait twice in case you know that 2nd call is always second. Also you could probably find a way to distinguish these 2 calls, maybe regexp could help you
s
@nutritious-honey-65632 I tried to wait twice but then cause they come in the same second they both go into the first one for some reason, and the 2nd one can't find anything since the 1st one handled both of them
m
@straight-pencil-91170 do the requests have the exact same call? same parameters, body, uri etc?
n
can you share the code, hide sensitive info
s
1 parameter in the body is different
g
Waiting for multiple network calls covered in my (paid) course https://cypress.tips/courses/network-testing
m
if you mean that a field in the body is different you can use something like
Copy code
cy.intercept('POST or GET', '/same-url*', {
  body: {
    name: 'Peter Pan',
  },
})
s
@most-baker-72677 And then it will intercept only the one with the body I want? (and can I provide like some of the body like the 1 parameter that is different?)
n
this will stub the response
m
aah, true...doh
s
@nutritious-honey-65632 Your video will help with this problem?
n
You could try, it is not video
3 Views