Simple and complete DOM testing utilities that encourage good testing practices.
Table of Contents
- The Problem
- This Solution
- Other Solutions
- Guiding Principles
You want to write maintainable tests for your Web UI. As a part of this goal, you want your tests to avoid including implementation details of your components and rather focus on making your tests give you the confidence for which they are intended. As part of this, you want your testbase to be maintainable in the long run so refactors of your components (changes to implementation but not functionality) don't break your tests and slow you and your team down.
dom-testing-library is a very light-weight solution for testing DOM nodes
(whether simulated with
JSDOM as provided by
default with jest or in the browser). The main utilities it provides involve
querying the DOM for nodes in a way that's similar to how the user finds
elements on the page. In this way, the library helps ensure your tests give you
confidence in your UI code. The
dom-testing-library's primary guiding
npm install --save-dev dom-testing-library
This library was not built to be used on its own. The original implementation
of these utilities was in the
We try to only expose methods and utilities that encourage you to write tests that closely resemble how your web pages are used.
Utilities are included in this project based on the following guiding principles:
- If it relates to rendering components, it deals with DOM nodes rather than component instances, nor should it encourage dealing with component instances.
- It should be generally useful for testing the application components in the way the user would use it. We are making some trade-offs here because we're using a computer and often a simulated browser environment, but in general, utilities should encourage tests that use the components the way they're intended to be used.
- Utility implementations and APIs should be simple and flexible.
At the end of the day, what we want is for this library to be pretty light-weight, simple, and understandable.
Thanks goes to these people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!