I am trying to add a wait to all requests to /graphql. I would like the requests to automatically wait. However, I am getting the following error:
Cypress detected that you returned a promise from a command while also invoking one or more cy commands in that promise.
I have tried multiple ways to add it (Note I am setting the alias as mentioned here):
Before(() => {
cy.intercept('POST', '**/graphql', handleGraphql);
});
function handleGraphql(req) {
req.alias = `gql${req.headers['query-id']}Query`;
// The different ways that I have tried:
setTimeout(() => cy.wait(`@gql${req.headers['query-id']}Query`), 100);
new Cypress.Promise(() => cy.wait(`@gql${req.headers['query-id']}Query`))
}
I then have also tried this function:
function handleGraphql(req) {
req.alias = `gql${req.headers['query-id']}Query`;
cy.wait(`@gql${req.headers['query-id']}Query`);
}
but then I get the following error:
Timed out retrying after 5000ms: cy.wait() timed out waiting 5000ms for the 1st request to the route: gql9b93b362-d715-4aae-928b-71b406381350Query. No request ever occurred.
I found that you can add some events to the req, but none of them seem to do what I want, as I am getting the returned a promise error from above.
function handleGraphql(req) {
req.alias = `@gql${req.headers['query-id']}Query`;
req.continue(() => {
cy.wait(`@gql${req.headers['query-id']}Query`);
});
}