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");
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.

Further reading

Problem with a question

Cypress · Junior · question 30

Test yourself

Take the Cypress · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz