Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Receipt form test
describe("New recipe form", () => {
const apiUrl = "https://cookbook.ack.ee/api/v1/recipes";
beforeEach(() => {
// Start server before each test to allow stubs
cy.server();
});
it("adds new recipe", () => {
// Define stub for our request
cy.route({
method: "POST",
url: apiUrl,
response: {}
}).as("postAddRecipe"); // Visit page with form (root in our case)
cy.visit("/"); // Fill in form values and submit it
cy.get('input[name="name"]').type("Ackee pasta with salmon");
cy.get('input[name="duration"]').type("40");
cy.get("textarea").type("Boil water, add pasta and cook salmon");
cy.get('button[type="submit"]').click(); // Wait for request to resolve
cy.wait("@postAddRecipe"); // Test success label has been displayed
cy.get("#successLabel").contains("Recipe was successfully created!");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.