Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

91
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!