react-testing
БесплатноБез исполняемых скриптовНе проверенUSE WHEN writing, fixing or reviewing a React Testing Library test for a component, hook or context provider, even one small test, or when asked for an…
от mintuz★ 38 звёзд на GitHubОб этом скилле
React Testing Library
For a page or widget not built with React, use the frontend-testing skill. For the TDD workflow, use the tdd skill.
Core rules
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.
- Query by accessible role, label or visible text.
- Add
{ name }togetByRoleonly when the element has an accessible name. Content names abutton,linkorheading.aria-labeloraria-labelledbynames an element whose role accepts an author-supplied name. A plain<li>takes no name from its text, so query it by that text. - Assert the call count with
toHaveBeenCalledTimesas well as the arguments.toHaveBeenCalledWithalone does not prove the number of calls. - Do not test component state or methods. Do not assert on a class name, test id or handler name when accessible output proves the same behaviour. Do not use shallow rendering.
- Do not wrap
render(),userEventcalls or async queries inact(). RTL wraps them. - Do not call
cleanup()in a test file. RTL cleans up automatically when the runner exposes a globalafterEach. In Vitest, that needsglobals: trueor oneafterEach(cleanup)in a shared setup file. When the project keeps globals off, put that call in the setup file, removecleanupfrom every test file and leave the config unchanged. - Render through a factory function in each test, not a shared
beforeEachrender.
Project libraries
Use the runner, matchers and helpers the project already has. Do not add a testing dependency that nobody asked for (principle-reuse-before-building).
- If
@testing-library/user-eventis installed, createuserEvent.setup()in each test. If not, usefireEventand say thatuser-eventmodels the interaction more closely. - If the setup registers jest-dom matchers, use them, such as
toBeInTheDocument(). If not, assert absence withtoBeNull()and text withtextContent. - Before you write a network stub or custom render helper, use the project's existing one, such as a
stubApifunction, an MSWserveror arenderWithProvidershelper.
Scope
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:
- Say it is end-to-end work. Name each external system from the request that it crosses.
- Recommend a browser-driven tool by name, such as Playwright or Cypress, for the journey.
- Name each slice RTL can still cover with the network boundary mocked: its component and the behaviour to assert (
principle-state-the-scope).
Do not offer a test that fakes those external systems as an equivalent of the journey.
Test allocation
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.
Asynchronous results
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 a positive assertion, such as
await screen.findByText(...). - Then assert the absence with a
queryBy*query andnot.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().
Hooks and context
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 a
Установить react-testing в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл react-testing?
USE WHEN writing, fixing or reviewing a React Testing Library test for a component, hook or context provider, even one small test, or when asked for an end-to-end journey inside a Vitest or React Testing Library suite; NOT WHEN changing the component itself (react), testing XState actors or @xstate/react (xstate), or writing a Playwright or Cypress test; covers renderHook, providers, async results, forms and false-pass anti-patterns, and declines end-to-end journeys with the testable slices.
Как установить скилл react-testing?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл react-testing запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic