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

126
Vistas
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 Respuestas
Responde la pregunta

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 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