Write, fix, and improve tests for React components, hooks, and pages.
Copy the install command and let the AI configure it · recommended for beginners
Please install the "react-testing" skill from askskill: 1. Download https://raw.githubusercontent.com/affaan-m/ECC/main/skills/react-testing/SKILL.md 2. Save it as ~/.claude/skills/react-testing/SKILL.md 3. Reload skills and tell me it's ready
Write React Testing Library + Vitest tests for this React button component. Cover rendering, click behavior, disabled state, and accessibility assertions, and explain the purpose of each test.
Runnable component test code with key interaction coverage and accessibility checks.
This React component test is flaky because of API requests. Use MSW to mock the network calls, refactor the test cases, and explain why this approach is more reliable.
A stable MSW-based test implementation plus an explanation of the failure and fix.
Based on this React page feature description, decide which scenarios should be covered by component tests and which are better suited for Playwright or Cypress end-to-end tests, then provide a testing-layer recommendation.
A clear testing strategy that separates component-test scope from end-to-end coverage.
Comprehensive React testing patterns for behavior-focused component tests, custom hook tests, accessibility assertions, and network-level mocking.
Test what the user sees and does, not implementation details.
A test should:
userEventA test should NOT:
| Runner | When | Note |
|---|---|---|
| Vitest | Vite, Remix, modern setups | Faster, native ESM, Jest-compatible API |
| Jest | Next.js, CRA, established repos | Default for many React projects |
| Playwright Component Testing | Real browser engine needed | Use when JSDOM lacks the required feature |
| Cypress Component Testing | Real browser, Cypress already in use | Alternative to Playwright CT |
Pick one. Do not run RTL + Vitest AND Playwright CT in the same repo unless you have a clear lane separation.
React Testing Library exposes queries in three tiers — use top-down:
getByRole, getByLabelText, getByPlaceholderText, getByText, getByDisplayValuegetByAltText, getByTitlegetByTestId// Best
screen.getByRole("button", { name: /save/i });
// OK for inputs
screen.getByLabelText("Email");
// Last resort
screen.getByTestId("save-btn");
Variants:
getBy* — throws if no matchqueryBy* — returns null (use for "assert absence")findBy* — async, returns a Promise (use for elements that appear after async work)userEventimport userEvent from "@testing-library/user-event";
test("submits the form", async () => {
const user = userEvent.setup();
const onSubmit = vi.fn();
render(<UserForm onSubmit={onSubmit} />);
await user.type(screen.getByLabelText("Email"), "[email protected]");
await user.click(screen.getByRole("button", { name: /save/i }));
expect(onSubmit).toHaveBeenCalledWith({ email: "[email protected]" });
});
await userEvent callsuserEvent.setup() once per test, reuse the returned useruserEvent simulates a real browser sequence; fireEvent dispatches a single synthetic event — prefer userEvent// Element that appears after async work
expect(await screen.findByText("Loaded")).toBeInTheDocument();
// Side effect assertion
await waitFor(() => expect(saveSpy).toHaveBeenCalled());
// Element that should disappear
await waitForElementToBeRemoved(() => screen.queryByText("Loading"));
Never setTimeout + assertion — flaky. Use the matchers above.
Mock Service Worker mocks at the network layer. The component, hooks, and fetch library all behave exactly as in production.
// test/setup.ts
import { setupServer } from "msw/node";
import { http, HttpResponse } from "msw";
export const handlers = [
http.get("/api/users/:id", ({ params }) =>
HttpResponse.json({ id: params.id, name: "Alice" }),
),
http.post("/api/users", async ({ request }) => {
const body = await request.json();
return HttpResponse.json({ id: "new-id", ...body }, { status: 201 });
}),
];
…
Verify Laravel projects with environment checks, tests, security scans, and release readiness.
Audit ECC Tools cost anomalies and trace misuse, leakage, and duplicate jobs.
Practice test-driven development for Spring Boot features, fixes, and refactoring.
Search official USPTO records and organize reproducible patent and trademark research.
Learn idiomatic Rust patterns, ownership, concurrency, and robust error handling practices.
Design compliant PHI and PII protection patterns for healthcare applications.
Write and review React 18/19 components using modern best practices.
Optimize React and Next.js performance during coding, review, and refactoring.
Build accessible React and Next.js interfaces with robust UI accessibility patterns.
Interact with and test local web apps using Playwright for debugging and verification.
Handle UI changes, fixtures, screenshots, and visual testing in component explorer projects.
Create and maintain screenshot test fixtures for UI components effectively.