Cypress · Junior · Question 30 of 75
How do you wait for a request before asserting the UI?
cy.intercept("GET", "/api/orders").as("orders");
cy.visit("/orders");
cy.wait("@orders");- 1Use
cy.wait(3000)so the request has time to finish - 2Alias it with
cy.interceptand usecy.wait('@orders') - 3Requests can't be awaited, only the DOM can be checked
Show the answer
Correct answer: Alias it with cy.intercept and use cy.wait('@orders')
Explanation
Defining the intercept before the action ensures it catches the request. cy.wait('@alias') also yields the request and response for assertions.