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

122
Views
Need promise in order for Cypress not to pass test prematurely

I have the following simple test:

describe("smoke test", () => {
  it("visit site", async () => {
    cy.visit(SITE_URL);

    return new Promise((resolve) => cy.contains("banner text").should("be.visible").then(resolve));
  });
});

Cypress warns me that it is not necessary to return a promise. But if I remove it the test passes immediately, even if the site is not up:

describe("smoke test", () => {
  it("visit site", async () => {
    cy.visit(SITE_URL);

    cy.contains("banner text").should("be.visible");
  });
});

Is there a better way of fixing this test; is Cypress' warning wrong or is it something in my code?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Cypress already includes async under the hood, no need for it in code

describe("smoke test", () => {
  it("visit site", () => {
    cy.visit(SITE_URL);
    cy.contains("banner text").should("be.visible");
  });
});

If you want to do async stuff in your code, use .then(), to work with yielded promise. Don't use async, await as they won't work as expected probably... https://medium.com/@NicholasBoll/cypress-io-using-async-and-await-4034e9bab207

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!