React Testing Library
Question
What is React Testing Library?
Hint
RTL tests behavior, not implementation details.
Explanation
React Testing Library (RTL) tests React components by rendering them and interacting with the DOM as a user would. Philosophy: "The more your tests resemble the way your software is used, the more confidence they give you." Queries: getByRole, getByLabelText, getByText (prefer role/label over test IDs). fireEvent and userEvent for interactions. waitFor for async. RTL discourages testing implementation details (state, lifecycle, internal methods) — these change during refactoring but behavior should not. Combined with Jest for assertions. RTL tests survive refactoring because they test the output (what the user sees), not the internals.
Related Resources
Related Lessons
- React Testing
Learn React testing.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.