I want to execute the multiple times same API with different payloads, but it's not working.
it('call same api with different payload',()=>{
cy.intercept('PATCH', `**/user/1`,{name:'thava'} ).as("action1")
cy.intercept('PATCH', `**/user/1`,{name:'prakash'} ).as("action2")
cy.visit('../app/intercept-identical.html');
cy.get("#update-action1").click();
cy.wait(['@action1']);
cy.get("#update-action2").click();
cy.wait(['@action2']); // not working
})
When requests are identical, only one intercept
routeMatcherwill catch all the calls.To vary the response, one way is to respond with a function
Tested with
Note
req.reply(res => { res.send(...) }will not stub the request, it will only modify the response from the live server. If the server targeted is not able to accept 'PATCH', you will get an error.Overriding intercepts
If you update to the latest version of Cypress, you can simply over-write the intercept.
The last-added intercept will be the one to catch the request.