/web:react-testingfrom web
Guides writing, fixing, or reviewing React Testing Library tests for components, hooks, and context providers. Covers renderHook, providers, async results, forms, and false-pass anti-patterns. Declines non-React or Playwright/Cypress tests.
Ships in web. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
For a page or widget not built with React, use the frontend-testing skill. For the TDD workflow, use the tdd skill.
Test behaviour through public APIs: props in, rendered DOM out (principle-test-behavior-not-implementation). For each assertion, name a plausible wrong implementation that would still pass. Write the assertion that fails on it.
{ name } to getByRole only when the element has an accessible name. Content names a button, link or heading. aria-label or aria-labelledby names an element whose role accepts an author-supplied name. A plain <li> takes no name from its text, so query it by that text.toHaveBeenCalledTimes as well as the arguments. toHaveBeenCalledWith alone does not prove the number of calls.render(), userEvent calls or async queries in act(). RTL wraps them.cleanup() in a test file. RTL cleans up automatically when the runner exposes a global afterEach. In Vitest, that needs globals: true or one afterEach(cleanup) in a shared setup file. When the project keeps globals off, put that call in the setup file, remove cleanup from every test file and leave the config unchanged.beforeEach render.Use the runner, matchers and helpers the project already has. Do not add a testing dependency that nobody asked for (principle-reuse-before-building).
@testing-library/user-event is installed, create userEvent.setup() in each test. If not, use fireEvent and say that user-event models the interaction more closely.toBeInTheDocument(). If not, assert absence with toBeNull() and text with textContent.stubApi function, an MSW server or a renderWithProviders helper.RTL renders one component tree, in jsdom or a browser test runner. Keep every test inside that tree.
A request crosses that boundary when it needs a real network, a real email or a redirect to a third-party site. A demand for several real browsers is a coverage matrix for that journey, not a separate boundary. For such a request:
principle-state-the-scope).Do not offer a test that fakes those external systems as an equivalent of the journey.
Prefer integration tests over unit tests.
| Level | What to test | How many | Tools |
|---|---|---|---|
| Unit | Pure functions that hold a decision, such as a permission rule, a complex calculation or a shared utility | Each rule outside a component | Vitest, no renderer |
| Integration | Features, user flows, component interactions | Most tests | Vitest + Testing Library |
| E2E | Critical user journeys | Few, critical paths only | Playwright or Cypress |
Test a permission rule in a plain function without rendering React (react skill). Test a state machine as an actor (xstate skill). Keep those unit tests. Do not move their rule into a rendered test.
A view that loads or updates asynchronously shows its result after the first render. To assert that a value is absent from that result:
await screen.findByText(...).queryBy* query and not.toBeInTheDocument().An earlier absence check passes while the view still shows its loading state, so it proves nothing. Reach the result with awaited Testing Library APIs, not a fixed delay or an act() around render(). Use fake timers only when a timer is the behaviour under test. Then pass advanceTimers to userEvent.setup() and advance the clock with the runner's timer API.
When an async handler calls a callback, await the callback assertion, for example await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1)).
Assert a synchronous initial state, such as a collapsed panel, directly after render().
Use renderHook for hook-only behaviour. Its initialProps and rerender(props) reach the hook callback only, never the wrapper. Use the wrapper option to mount a provider with fixed props. When the test calls a state-changing hook callback directly, such as result.current.addItem(), wrap that call in act(). It runs outside RTL's auto-wrapped helpers.
When a provider prop must change, render a small consumer component with render(). Change the prop through that render result's rerender(). The rendered output is the public seam that the provider change must affect. Do not pass the new value through a mutable variable that the wrapper reads, or through a second mounted hook.
Write every assertion the supplied facts support, and keep that runnable test in the answer. When one expected outcome is undefined:
test.todo that states what is needed.principle-never-block-on-the-human).Do not invent copy, a role or a test id and assert it as though it was supplied. Do not delete the supported assertions because one path is undefined.
| Reference | Read when |
|---|---|
| components.md | Testing props to output, callbacks or conditional rendering |
| hooks.md | Using renderHook, result.current, act() or rerender() |
| context.md | Wrapping in providers or writing a custom render helper |
| forms.md | Testing inputs, submissions or validation |
| anti-patterns.md | Removing manual act(), manual cleanup(), beforeEach render, internals or shallow rendering |
| advanced.md | Testing loading states, error boundaries, portals or Suspense |
render() and renderHook() come from @testing-library/react. No enzyme shallow or mount.test.todo.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
react-testing-library, vitest, unit-testing, component-testing
npx claudepluginhub mintuz/skills --plugin web10 skills in this plugin
/browser-testingWHEN authoring or repairing real-browser journeys or automated screenshot comparisons with the project's selected runner; NOT DOM-only tests, interactive visual judgement or verification-recipe maintenance; provides native-runner fixtures, assertions and visual-comparison guidance./chatgpt-app-sdkWHEN building ChatGPT apps using the OpenAI Apps SDK and MCP; NOT for OpenAI API chat completions, agent frameworks, or MCP servers with no ChatGPT widget; create conversational, composable experiences with proper UX, UI, state management, and server patterns./cssUSE WHEN writing, fixing or reviewing plain CSS or Sass for a web page, even a one-line change, including a rule that loses to another, a third-party stylesheet you cannot edit, units, spacing between components, shorthands, skip links, hidden and focus styles, or deleting styles that look unused; NOT WHEN the project uses Tailwind (tailwind.config.js, utility classes, CVA variants, Tailwind theme tokens); produces CSS that wins the cascade without ID selectors or reactive !important, scales with the reader's text size, keeps spacing in the parent and deletes styles only on evidence./frontend-testingUSE WHEN testing non-React UI (vanilla JavaScript or TypeScript DOM code, a web component, or a Vue, Svelte or Angular component) with DOM Testing Library in Vitest or Jest with jsdom: writing, fixing or reviewing a test, or a request to add an end-to-end journey or a layout check to that suite; NOT WHEN the code or project uses React or React Testing Library (use web:react-testing), for XState actors (web:xstate), or for Playwright, Cypress or screenshot-comparison work in a real browser; covers queries, accessible names, userEvent, async results, network stubs and assertions that pass for the wrong reason, and declines what jsdom cannot prove while offering the part that fits./reactUSE WHEN changing the logic, data, props, state, Effects or rendered text of a React component, hook or page, even a one-line change; NOT WHEN the request is styling only (class names, Tailwind, CSS, dark mode, spacing, shadows) or tests only, or when it models submit, in-flight, loading, retry or failure states, even for a named React form (xstate covers that, including its React wiring); applies React 19 composition, state, Effect, structure, API and performance rules with only the project's installed libraries./refactoringWHEN you need a plan to refactor, restructure, or clean up working code and the test result is known, either green or a recorded failing set; NOT for new feature delivery or any behavior change; reversible-baseline safety with prioritized improvements.Other plugins' skills for the same job