Test UI components the way users use them
open sourceMITfree
Testing Library is a family of packages for testing UI components in a user-centric way: tests find elements the way a user would (by role, label or text) and interact with them, instead of reaching into implementation details, so refactors don't break them. The core, DOM Testing Library, queries and interacts with DOM nodes in JSDOM or a real browser, and it's wrapped for React, Angular, Vue and other frameworks, React Native and Cypress, with user-event for realistic interactions and jest-dom for DOM matchers. It isn't a test runner: it works with Jest, Vitest, Mocha or any environment with DOM APIs.
Problems it solves
- test my React components without testing implementation details
- find elements in a component test by role or label like a user would
- tests break every time I refactor a component even though it still works
- simulate realistic clicks and typing in a component test
- test Vue or Angular components from the user's point of view
Features
- queries by role, label, text and test id
- DOM Testing Library core, framework-agnostic
- wrappers for React, Angular, Vue, Svelte and React Native
- user-event for realistic interactions
- jest-dom custom matchers
- works with Jest, Vitest, Mocha or a real browser
Alternatives
The same job
These do what Testing Library does.
