Tengo un alias en el resguardo de mi dispositivo, así que esto funciona para mí:
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"); }); }); }); });pero esto no funcionará?
it("show something", () => { await cy.wait("@firstApiCall"); await cy.wait("@firstApiCall"); cy.get("test:something").should("exist"); }); Además, ¿cómo puedo evitar repetir cy.wait(apiCall) it cada bloque?
Probablemente falla con:
Unexpected reserved word 'await'. y eso se debe a que la palabra clave await solo se puede usar en funciones async , su función de devolución de llamada no es asíncrona.
Podrías escribir:
it("show something", async () => { await cy.wait("@firstApiCall"); await cy.wait("@firstApiCall"); cy.get("test:something").should("exist"); });Pero me pregunto por qué quieres hacerlo. Cypress hace un buen trabajo ejecutando los comandos en el orden en que están escritos ( https://docs.cypress.io/guides/core-concepts/introduction-to-cypress#Commands-Run-Serially ).
También dudo que tu ejemplo realmente funcione:
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"); }); }); }); }); No usa alias firstApiCall y 2ndApiCall , por lo que Cypress no sabe qué esperar.