Loading...
Loading...
Cypress end-to-end and component testing patterns for web apps: reliable selectors, stable waits, network stubbing, auth handling, CI parallelization, and flake reduction
npx skill4agent add bobmatnyc/claude-mpm-skills cypressnpm i -D cypress
npx cypress open// cypress/e2e/health.cy.ts
describe("health", () => {
it("loads", () => {
cy.visit("/");
cy.contains("Hello").should("be.visible");
});
});data-testiddata-cy<button data-testid="save-user">Save</button>cy.get('[data-testid="save-user"]').click();cy.wait(1000)cy.intercept("GET", "/api/users/*").as("getUser");
cy.visit("/users/1");
cy.wait("@getUser");
cy.get('[data-testid="user-email"]').should("not.be.empty");cy.interceptcy.intercept("GET", "/api/users/1", {
statusCode: 200,
body: { id: "1", email: "a@example.com" },
}).as("getUser");cy.session// cypress/support/commands.ts
Cypress.Commands.add("login", () => {
cy.session("user", () => {
cy.request("POST", "/api/auth/login", {
email: "test@example.com",
password: "password",
});
});
});// e2e spec
beforeEach(() => {
cy.login();
});npx cypress open --component// cypress/component/Button.cy.tsx
import React from "react";
import Button from "../../src/Button";
describe("<Button />", () => {
it("clicks", () => {
cy.mount(<Button onClick={cy.stub().as("onClick")}>Save</Button>);
cy.contains("Save").click();
cy.get("@onClick").should("have.been.calledOnce");
});
});// cypress.config.ts
import { defineConfig } from "cypress";
export default defineConfig({
video: false,
screenshotOnRunFailure: true,
retries: { runMode: 2, openMode: 0 },
});cy.wait(1000)cy.sessiondata-testidshould("be.visible")