# Testing React

> Use when writing or modifying tests for React hooks.

- Skill: `landonschropp/testing-react` (Agent Skill)
- Install (CLI): `npx skillmds@latest add landonschropp/testing-react`
- Raw SKILL.md: https://api.skillmd.com/api/skills/landonschropp/testing-react/raw
- Safety review: PASS (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Web & Frontend
- Author: LandonSchropp (https://skillmd.com/u/landonschropp)
- Updated: 2026-08-19
- Page: https://skillmd.com/skills/landonschropp/testing-react

---


# Testing React Hooks

Use `renderHook` and `act` from `@testing-library/react`. Don't write a probe component — `renderHook` is the affordance for testing a hook in isolation.

```tsx
import { useMyHook } from "./use-my-hook.ts";
import { act, renderHook } from "@testing-library/react";

const { result, rerender, unmount } = renderHook(() => useMyHook(arg));
expect(result.current).toBe(/* ... */);
```

`renderHook` needs DOM globals. A typical React project provides them through its configured test environment (jsdom or happy-dom), so no per-test setup is required.

