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

101
Vistas
avoid callback with await cypress doesn't work?

I have alias on my fixture stub, so this is working for me:

describe("some page", () => {
  beforeEach(() => {
    cy.intercept("/users", {
      fixture: users.json,
    });
    cy.visit("/somewhere");
  });

  it("show something", () => {
    cy.wait("@firstApiCall").then(() => {
      cy.wait("@2ndApiCall").then(() => {
        cy.get("test:something").should("exist");
      });
    });
  });
});

but this won't work?

it("show something", () => {
  await cy.wait("@firstApiCall");
  await cy.wait("@firstApiCall");

  cy.get("test:something").should("exist");
});

Also, how can I avoid repeating cy.wait(apiCall) in each it block?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It probably fails with:

Unexpected reserved word 'await'.

and that's because await keyword could be used only in async functions, your callback function is not async.

You might write:

it("show something", async () => {
  await cy.wait("@firstApiCall");
  await cy.wait("@firstApiCall");

  cy.get("test:something").should("exist");
});

But I wonder why do you want to do it? Cypress does a good job running the commands in the order in which they are written (https://docs.cypress.io/guides/core-concepts/introduction-to-cypress#Commands-Run-Serially).

I also doubt your example actually works:

describe("some page", () => {
  beforeEach(() => {
    cy.intercept("/users", {
      fixture: users.json,
    });
    cy.visit("/somewhere");
  });

  it("show something", () => {
    cy.wait("@firstApiCall").then(() => {
      cy.wait("@2ndApiCall").then(() => {
        cy.get("test:something").should("exist");
      });
    });
  });
});

You don't alias firstApiCall and 2ndApiCall, so Cypress doesn't know what to wait for.

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