citypaul/.dotfiles/react-testing
Claude Code and agent skill by citypaul/.dotfiles
- community
- ext:[{"type":"hook","description":"Pre/post lifecycle hooks"},{"type":"context","description":"Custom context provider definitions"}]
Checking that the SKILL.md file is still in the repository.
React component testing patterns including components, hooks, context, and forms. Covers Vitest Browser Mode with vitest-browser-react and @testing-library/react. Use when testing React applications. For general UI testing patterns, see the front-end-testing skill.
Install
npx vskill@latest install citypaul/.dotfiles/react-testingSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
The same SKILL.md was published earlier as citypaul/.dotfiles/react-testing.
React Testing
For general UI testing patterns (queries, events, async, accessibility, MSW), load the front-end-testing skill. For TDD workflow, load the tdd skill.
Find every element the way a person perceives it — never by `data-testid`, a CSS class, or a selector, and least of all because the component already carries one. A control is found by getByRole with its accessible name (getByLabelText for a field). An element with no role — a count line, a status message, a paragraph of copy, a bare <span> of text — is found by the words it shows: getByText(/3 of 7 items/), then asserted on that same locator (toBeVisible(), toHaveAttribute(...)). Never fetch a handle by test id first just to assert its content. If nothing about the element is perceivable enough to query, that is a finding about the component: give it the role, label, or accessible name its purpose implies, and query that.
For flow logic driving the component, load xstate: the machine is tested headlessly and the component test touches only the DOM, so a component test must never assert machine state. If the component under test holds a submitting/isLoading flag in useState, that is the signal the flow escaped its machine — xstate owns that call. For performance changes to the same code, load react-performance, whose rule is that behaviour tests stay unchanged and green.
Follow the tdd skill's canonical fast-feedback and watcher-lifecycle policy plus the front-end-testing skill's browser-specific differences. React adds no separate Vitest graph guarantee: prefer the repository-owned watcher, use diff-selected watch only under the canonical version/configuration proof, and keep every affected app/package consumer eligible through the root graph. Exact files remain RED/debug-only. At PR readiness, stop watchers and apply the target repository's mutation policy plus complete non-watch UI/project gate.
Deep-dive resources are in the resources/ directory. Load them on demand:
| Resource | Load when... | |
|---|---|---|
resources/testing-library-react-legacy.md | Working in a @testing-library/react + jsdom codebase — sync render, screen queries, imported act, render helpers, legacy form/hook/context examples |
Vitest Browser Mode with React
Prefer vitest-browser-react when the claim depends on real rendering, events, focus, CSS, accessibility, or browser APIs and the repository supports the harness or the added cost is justified. Keep an existing stable @testing-library/react/jsdom harness, or use a lighter environment, when it already proves pure hook, provider, or component logic.
Setup
Extend the Browser Mode config from the front-end-testing skill with the React plugin and vitest-browser-react. Apply that skill's repository-package-manager, exact-version, authorization, and local-binary setup policy:
Component Testing
Key differences from `@testing-library/react`:
render()andrenderHook()are async — useawait- Returns a
screenscoped to the rendered component - Use
expect.element()for auto-retrying assertions - No
act()wrapper needed for component interactions via locators — CDP events + retry handle timing.renderHookstate updates still needact(returned byrenderHook, see below) - Auto-cleanup happens before each test (not after), so components stay visible for debugging
Testing Props and Callbacks
Testing Conditional Rendering (with MSW)
Browser Mode tests run in a real browser, so use MSW's setupWorker (msw/browser) — not setupServer. Start the worker in a setup file and override per test with worker.use(). Full setup: front-end-testing skill, resources/msw.md.
Testing Hooks with renderHook
renderHook() is async and returns act alongside result — use that act for hook state updates:
Testing Context Providers
For hooks that need context:
Testing Forms
Testing Loading States
Testing Error Boundaries
Testing Portals
The returned screen is scoped to the rendered component — for portal content, use the document-wide page from vitest/browser.
Testing Suspense
React Server Components
RSCs can't be tested in Browser Mode component tests — they execute on the server, not in the browser. Test them with e2e tests (Playwright against a running app) or unit tests of logic extracted from the component. Client components ('use client') test normally with vitest-browser-react.
React-Specific Anti-Patterns
1. Unnecessary act() wrapping
❌ WRONG - Manual act() around renders and interactions
✅ CORRECT - Locator events handle timing
When you DO need `act()`: hook state updates via renderHook (use the act it returns). In @testing-library/react, RTL auto-wraps render/userEvent/waitFor — see resources/testing-library-react-legacy.md.
2. Testing component internals
❌ WRONG - Accessing component internals
✅ CORRECT - Test rendered output
3. Shallow rendering — and its modern spelling, mocking a child component
Never `vi.mock` a component the app under test owns. Replacing a child with a stand-in is shallow rendering by another name, and it is now the far more common form. When a request asks you to stand something in for a child because its markup is somebody else's problem, honour the concern, not the mechanism: render the whole tree and assert only the parent's own observable facts — which items are on screen, the count line, the empty state — and pin none of the child's markup. Mock across a real boundary (network via MSW, clock, randomness), never inside your own component tree.
❌ WRONG - Child replaced by a stand-in, or shallow rendered
✅ CORRECT - Full rendering
Why: Shallow rendering hides integration bugs between parent/child components.
4. Shared renders and cleanup ownership
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingclaude/.claude/skills/react-testing/SKILL.md
Popularity
- Repository stars
- 618
- Repository forks
- 78
- 7-day trend score
- 32
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 11 Apr 2026, 7 months ago.
Extension points
hookPre/post lifecycle hookscontextCustom context provider definitions
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/citypaul/.dotfiles/react-testing)