React Component Testing

Test React components with Testing Library — render, query by role, and assert on user-visible behavior.

alexngai Updated
skill-tree CLI — list, search, read, and fork versioned agent skills

File contents

React Component Testing

Test what the user sees, not implementation details.

  1. render(<Component />) from @testing-library/react.
  2. Query by accessible role: screen.getByRole('button', { name: /save/i }).
  3. Drive interactions with userEvent, then assert on the resulting DOM.
  4. Avoid container.querySelector and snapshot-everything tests — they break on refactors.

Prefer findBy* for async UI and getBy* for content that is already present.

alexngai/skill-tree commit 9fcc8bb881

Frequently asked questions

npx get-skill add alexngai/react-component-testing