React · Senior · Question 43 of 75
What principle underlies React Testing Library?
- ✓Correct answer: Test behavior the way the user sees it: roles, text, labels
- 2Test the internal state and instance methods of components
- 3Snapshot the whole DOM and compare it after every action
Explanation
Queries like getByRole('button', { name: 'Save' }) check behavior and accessibility at the same time and don't break when internals are refactored. Interactions are simulated with user-event. Tests of implementation details are brittle and guarantee little.