Skip to content

Instantly share code, notes, and snippets.

@jessesanders
Created December 7, 2018 19:25
Show Gist options
  • Save jessesanders/83e1f6874b90f8460320a093ad6b5f7e to your computer and use it in GitHub Desktop.
Save jessesanders/83e1f6874b90f8460320a093ad6b5f7e to your computer and use it in GitHub Desktop.
Cypress example on waiting for stubbed responses to return
cy.server();
// create aliases
cy.route("activities/*", "fixture:activities").as("getActivities");
cy.route("messages/*", "fixture:messages").as("getMessages");
// visit the dashboard, which should make requests that match
// the two routes above
cy.visit("http://localhost:8888/dashboard");
// pass an array of Route Aliases that forces Cypress to wait
// until it sees a response for each request that matches
// each of these aliases
cy.wait(["@getActivities", "@getMessages"]);
// these commands will not run until the wait command resolves above
cy.get("h1").should("contain", "Dashboard");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment