React Testing Library Skill
Quick Navigation
Installation
Install: npm install --save-dev @testing-library/react @testing-library/dom. Recommended extras: @testing-library/user-event and @testing-library/jest-dom. React 19 requires v16.1.0+.
Core Philosophy
"The more your tests resemble the way your software is used, the more confidence they can give you."
Avoid testing:
- Internal state of components
- Internal methods
- Lifecycle methods
- Child component implementation details
Test instead:
- What users see and interact with
- Behavior from user's perspective
- Accessibility (queries by role, label)
Query Priority
Use queries in this order of preference:
1. Accessible to Everyone (Preferred)
2. Semantic Queries
3. Test IDs (Escape Hatch)
Query Types
When to use:
getBy*— element existsqueryBy*— element may not exist (assertions likeexpect(...).not.toBeInTheDocument())findBy*— element appears asynchronously
Basic Test Pattern
User Events
Always use @testing-library/user-event over fireEvent:


