The testing library focused on user behavior
Testing Library is a family of JavaScript testing libraries that promotes writing tests from the user's perspective instead of implementation details. Available for React, Vue, Angular, Svelte, and other frameworks, it provides utilities for finding elements as users perceive them, through text, ARIA roles, and labels, making tests more robust and meaningful.
Testing Library is the most widely adopted component testing library in the React ecosystem and has high demand in any frontend position that includes testing. It is the standard recommended by the React team for component tests.
Requires mastery of JavaScript or TypeScript and of the component framework used. Familiarity with testing concepts like mocking, assertions, and Jest is essential. Knowledge of web accessibility and ARIA roles facilitates writing tests with the correct selectors.
Testing Library is used to develop:
Testing Library is adopted by:
Testing Library is widely used in production environments such as:
Testing Library offers multiple mechanisms to scale applications:
Accessibility-based selectors that promote accessible interfaces by design.
Tests resistant to refactoring since they don't depend on implementation details.
Intuitive API with userEvent that simulates real user interactions.
Initial learning curve for developers accustomed to testing by implementation.
Some advanced use cases require additional configuration of providers and mocks.
Does not cover E2E tests that require a real browser with all browser APIs.
Considerations
Enzyme allows accessing component internals like state and methods, but generates fragile tests that break with refactoring. Testing Library promotes more robust behavior-focused tests, being the currently recommended option.