DEV Community

Discussion on: How to use stub multiple API requests dynamically in Cypress

Collapse
digitaledawn profile image
Aurore Trunelle Author • Edited on

I don't think this fit what we needed to achieve. With this,apolloResponses is going to be returned as the response for all request whether we want apolloResponses to have multiple responses and be matched against the request payload parameters dynamically.

(apolloResponses was meant to be articlesResponses in this example 🤦‍♀️, I updated that.)

Collapse
dxcjbeck profile image
Jonathan Matthew Beck • Edited on

What I meant to say is can you do away with the external dependency of xhook and use the cypress api instead:

beforeEach(() => {
cy.server({ method: 'POST' })
cy.route({
method: 'POST',
url: '**/articles',
onResponse: (xhr) => {
// insert your JSON filtering code here
}
})
})

docs.cypress.io/api/commands/route...

Thread Thread
digitaledawn profile image
Aurore Trunelle Author • Edited on

That was the first thing I tried but that didn't work for this use case. I wish it did.