Reputation: 3593
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?
Upvotes: 0
Views: 631
Reputation: 206
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
Upvotes: 1