Workflow Testing

Test a React Component

Workflow for testing React components with user-centric tests

testingreactfrontend
CLAUDE.md

When testing a React component:

  1. Render the component with minimal required props.
  2. Test what the user sees: query by role, label text, or test ID — not by class name or component internals.
  3. Test interactions: click buttons, type in inputs, submit forms. Verify the visible result.
  4. Test conditional rendering: verify elements appear and disappear based on props and state.
  5. Test loading and error states if the component fetches data.
  6. Don’t test implementation details: don’t assert on state values, hook calls, or internal method invocations.
  7. 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.

get crystl