Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

426
Vistas
Cypress: Wait for all requests to /graphql endpoint

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`);
  });
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Cypress detected that you returned a promise from a command... refers to the fact that you are waiting on the intercept alias within the handler.

Since the handler is event response code, the usual pattern is

cy.intercept(...)  // set up the listener

cy.visit(...)  // trigger the events (might also be from UI evnt like click())

cy.wait('@my-alias')

But this means the aliases should be known ahead of time.

Simplest is if you can find out all the ids,

const aliases = ['1', '2', '3'].map(id => `@gql${id}Query`)

const handleGraphql = (req) => req.alias = `gql${req.headers['query-id']}Query`;

before(() => {
  cy.intercept('POST', '**/graphql', handleGraphql)  // set up the listener
})

it('waits for all ids', () => {
  cy.visit(...)  // trigger the events (might also be from UI event like click())

  cy.wait(aliases)
}

If you can't be specific about the ids, then you either need to wait an arbitrary time for all requests to happen (which is flaky if the wait is too short, or annoying if the wait is too long) or assert an element or other DOM artefact that only appears after all requests are finished.


Your id's are generated, so don't use them in the alias. Use a "generic" alias and wait for the required count

const calls = 4

before(() => {
 cy.intercept('POST', '**/graphql').as('gqlQuery')
})

it('waits for all ids', () => {
 cy.visit(...)  // trigger the events (might also be from UI event like click())

 cy.wait(`@gqlQuery.${calls}`)
}

There's some warnings around the alias.n syntax being undocumented, but you could sub-in

Cypress._.times(calls => cy.wait('@gqlQuery')
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda