Simple and complete DOM testing utilities that encourage good testing practices.
Build Status Code Coverage version downloads MIT License All Contributors PRs Welcome Code of Conduct Discord
Watch on GitHub Star on GitHub Tweet
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.
The 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
principle is:
The more your tests resemble the way your software is used, the more confidence they can give you.
This module is distributed via npm which is bundled with node and
should be installed as one of your project's devDependencies
:
npm install --save-dev @testing-library/dom
Read the docs (and discover framework and tool-specific implementations) at testing-library.com
The more your tests resemble the way your software is used, the more confidence they can give you.
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):
Kent C. Dodds
💻 📖 🚇
Greg Bergé
🤔 Ryan Castner
Ryan Castner
📖 Daniel Sandiego
Daniel Sandiego
💻 Paweł Mikołajczyk
Paweł Mikołajczyk
💻 Alejandro Ñáñez Ortiz
Alejandro Ñáñez Ortiz
📖 Matt Parrish
Matt Parrish
🐛 💻 📖
Justin Hall
📦 Anto Aravinth
Anto Aravinth
💻
Jonah Moses
📖 Łukasz Gandecki
Łukasz Gandecki
💻
Ivan Babak
🐛 🤔 💻 📖 Jesse Day
Jesse Day
💻 Ernesto García
Ernesto García
💬 💻 📖
Josef Maxx Blake
💻 📖
Alex Cook
📖 💡 👀 Daniel Cook
Daniel Cook
💻 📖
Thomas Chia
🐛 💻 Tim Deschryver
Tim Deschryver
💻
Alex Krolick
💻 Maddi Joyce
Maddi Joyce
💻
Peter Kamps
🐛 💻
Jonathan Stoye
📖 💻 Sanghyeon Lee
Sanghyeon Lee
💡 Justice Mba
Justice Mba
💻 📖 🤔 Wayne Crouch
Wayne Crouch
💻 Ben Elliott
Ben Elliott
💻 Ruben Costa
Ruben Costa
💻
Robert Smith
🐛 🤔 📖 dadamssg
dadamssg
💻 Neil Kistner
Neil Kistner
💻
Ben Chauvette
💻 Jeff Baumgardt
Jeff Baumgardt
💻 📖 Matan Kushner
Matan Kushner
💻 📖 🤔
Alex Wendte
💻 📖
Tamas Fodor
📖 Benjamin Eckardt
Benjamin Eckardt
💻 Ryan Campbell
Ryan Campbell
📖 Taylor Briggs
Taylor Briggs
John Gozde
💻 C. T. Lin
C. T. Lin
📖 Terrence Wong
Terrence Wong
💻
Soo Jae Hwang
💻 Royston Shufflebotham
Royston Shufflebotham
🐛 💻 📖
Vadim Brodsky
💻 Eunjae Lee
Eunjae Lee
💻 David Peter
David Peter
💻 Shy Alter
Shy Alter
💻 📖 Łukasz Makuch
Łukasz Makuch
📦
Tyler Haas
💻
Vesa Laakso
💻
Tulsi Sapkota
💻 Tiago Nunes
Tiago Nunes
💻
JaxCavalera
💻 👀 bopfer
bopfer
Jan Pfitzner
💻
David
💻 Diego Hernandez
Diego Hernandez
💻
Alex Young
💻 Paul Armstrong
Paul Armstrong
💻
Tamás Szabó
💻
Dylan Piercey
💻
Michael Lasky
💻
Sebastian Silbermann
💻
Dylan Vann
💻 Adrià Fontcuberta
Adrià Fontcuberta
💻
Thomas Lombart
💻 Sam Horton
Sam Horton
💻
Andrew Hill
💻 Jan Amann
Jan Amann
💻
Brais Piñeiro
💻
Dominykas Blyžė
💻
Olzhas Askar
💻
Max Belsky
💻
Michael Mantel
Tom Nagle
💻 Westbrook Johnson
Westbrook Johnson
💻
Mohammad Aziz
💻
seetdev
Xavier Garcia Buils
💻
aw-davidson
💻
Michaël De Boey
💻 Minh Nguyen
Minh Nguyen
💻 Egill Sveinbjörnsson
Egill Sveinbjörnsson
💻
Pavel Pustovalov
📖 Adam Palaniuk
Adam Palaniuk
💻
Yama-Tomo
💻
Aaron Pettengill
💻
Kate W. Boyd
💻 Rahul Suryakanth
Rahul Suryakanth
💻
Jamie
💻
Nicolas Stepien
💻 Ken Powers
Ken Powers
💻 Michał Zdunek
Michał Zdunek
💻 Ali Nasserzadeh
Ali Nasserzadeh
💻 Darek Kay
Darek Kay
📖 💻
Lukas
💻
Tom Crockett
💻
Kevin Brewer
💻
Ben Monro
💻 🤔
Stephan Meijer
🤔 💻
João Forja
💻
Nick McCurdy
📖 💻
Caleb Meredith
💻 Marco Moretti
Marco Moretti
💻
Travis Jefferson
💻
Maciej Jastrzebski
🐛 Geoff Harcourt
Geoff Harcourt
💻 Josh Goldberg
Josh Goldberg
💻
Ken Gregory
💻
Jacob Paris
💻
keiya sasaki
📖
Idan Entin
💻
Deniz Susman
💻 Bianca Del Carretto
Bianca Del Carretto
Josh Lalonde
💻
Ioannis Papadopoulos
💻
Maxwell Newlands
💻
Jared Luxenberg
💻
snizhana
💻
Michael van Engelshoven
👀 Asher Tuggle
Asher Tuggle
🐛 Winter LaMon
Winter LaMon
💻
Victor Cordova
💻
slowselfip
🐛 Dmitry Semigradsky
Dmitry Semigradsky
💻
Adam
💻
balavishnuvj
💻 Chris Colborne
Chris Colborne
💻 Romain Trotard
Romain Trotard
💻 Thomas Marshall
Thomas Marshall
💻
johnjessewood
🐛 💻 Ari Perkkiö
Ari Perkkiö
🐛 💻 📖
Nathan Force
💻 Philipp Fritsche
Philipp Fritsche
💻 Renato Alencar
Renato Alencar
💻
Simen Bekkhus
🐛 Dan Abramov
Dan Abramov
🐛 👀 Matan Borenkraout
Matan Borenkraout
💻 simcha90
simcha90
💻
Amit Miran
🚇 Dominik Lesch
Dominik Lesch
📖 Gareth Jones
Gareth Jones
💻
Rayat Rahman
💻 Nik Savchenko
Nik Savchenko
💻 Kevin Fleischman
Kevin Fleischman
💻
Beth Hitch
💻
Jack Laurence
💻 SantoJambit
SantoJambit
💻 Yashu Mittal
Yashu Mittal
📖 Ian VanSchooten
Ian VanSchooten
💻 Vanya Prokopovich
Vanya Prokopovich
🐛 James Nail
James Nail
🐛 Rob Caldecott
Rob Caldecott
🐛
Dennis273
💻 Jackson Hardaker
Jackson Hardaker
Robin Drexler
💻 Omer Dolev
Omer Dolev
💻 Lirlev48
Lirlev48
💻 Tarnay Kálmán
Tarnay Kálmán
💻 Than Hutchins
Than Hutchins
💻
This project follows the all-contributors specification. Contributions of any kind welcome!