Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

94
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda