Test a React Component
Workflow for testing React components with user-centric tests
CLAUDE.md
When testing a React component:
- Render the component with minimal required props.
- Test what the user sees: query by role, label text, or test ID — not by class name or component internals.
- Test interactions: click buttons, type in inputs, submit forms. Verify the visible result.
- Test conditional rendering: verify elements appear and disappear based on props and state.
- Test loading and error states if the component fetches data.
- Don’t test implementation details: don’t assert on state values, hook calls, or internal method invocations.
- If the component has complex logic, extract it into a custom hook and test the hook separately.
Copy this workflow into your CLAUDE.md or agent config file so your agent follows this process automatically.