How is React Testing Library different from Enzyme?
Enzyme tested implementation details like instance methods and state. RTL tests behavior. Enzyme tests break on refactors; RTL tests survive them. This is why the React team recommends RTL.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in React Testing Interview Questions With Answers
RTL is a library for testing React components the way a user uses them: rendering, finding by role and text, and simulating events. Use it because tests that resemble user behavior give more confidence and survive refactors.
Role and text queries like getByRole and getByText. These query what the user experiences and double as accessibility checks. Test ids are a fallback; class names should be avoided as they tie tests to styling.
Use findBy queries, which wait for the element to appear, or waitFor to wait for an async condition. Avoid getBy for async results because it does not wait and throws immediately if the element is not present yet.
Still have questions?
Browse all our FAQs or reach out to our support team
