6 min read
•Question 30 of 48mediumTesting React Components
Writing tests with React Testing Library.
Testing Philosophy
React Testing Library focuses on testing components the way users interact with them.
Key Principles
- Test behavior, not implementation
- Query by accessibility (role, label)
- Avoid testing internal state
Common Queries
- getByRole, getByText, getByLabelText
- findBy* (async), queryBy* (returns null)