DOM Testing Library

octopus

Simple and complete DOM testing utilities that encourage good testing practices.

[**Read the docs**](https://testing-library.com/dom) | [Edit the docs](https://github.com/testing-library/testing-library-docs)

[![Build Status][build-badge]][build] [![Code Coverage][coverage-badge]][coverage] [![version][version-badge]][package] [![downloads][downloads-badge]][npmtrends] [![MIT License][license-badge]][license] [![All Contributors][all-contributors-badge]](#contributors) [![PRs Welcome][prs-badge]][prs] [![Code of Conduct][coc-badge]][coc] [![Discord][discord-badge]][discord] [![Watch on GitHub][github-watch-badge]][github-watch] [![Star on GitHub][github-star-badge]][github-star] [![Tweet][twitter-badge]][twitter]
TestingJavaScript.com Learn the smart, efficient way to test any JavaScript application.
## Table of Contents - [The Problem](#the-problem) - [This Solution](#this-solution) - [Installation](#installation) - [Documentation](#documentation) - [Guiding Principles](#guiding-principles) - [Contributors](#contributors) - [LICENSE](#license) ## The Problem 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. ## This Solution The `DOM Testing Library` is a very light-weight solution for testing DOM nodes (whether simulated with [`JSDOM`](https://github.com/jsdom/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.][guiding-principle] ## Installation This module is distributed via [npm][npm] which is bundled with [node][node] and should be installed as one of your project's `devDependencies`: ``` npm install --save-dev @testing-library/dom ``` > [**Docs**](https://testing-library.com/docs/install) ## Documentation Read the docs (and discover framework and tool-specific implementations) at [testing-library.com](https://testing-library.com/dom) ## Guiding Principles > [The more your tests resemble the way your software is used, the more > confidence they can give you.][guiding-principle] 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: 1. If it relates to rendering components, it deals with DOM nodes rather than component instances, nor should it encourage dealing with component instances. 2. 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. 3. 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. ## Contributors Thanks goes to these people ([emoji key][emojis]):
Kent C. Dodds
Kent C. Dodds

๐Ÿ’ป ๐Ÿ“– ๐Ÿš‡ โš ๏ธ
Greg Bergรฉ
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
Justin Hall

๐Ÿ“ฆ
Anto Aravinth
Anto Aravinth

๐Ÿ’ป โš ๏ธ ๐Ÿ“–
Jonah Moses
Jonah Moses

๐Ÿ“–
ลukasz Gandecki
ลukasz Gandecki

๐Ÿ’ป โš ๏ธ ๐Ÿ“–
Ivan Babak
Ivan Babak

๐Ÿ› ๐Ÿค” ๐Ÿ’ป ๐Ÿ“–
Jesse Day
Jesse Day

๐Ÿ’ป
Ernesto Garcรญa
Ernesto Garcรญa

๐Ÿ’ฌ ๐Ÿ’ป ๐Ÿ“–
Josef Maxx Blake
Josef Maxx Blake

๐Ÿ’ป ๐Ÿ“– โš ๏ธ
Alex Cook
Alex Cook

๐Ÿ“– ๐Ÿ’ก ๐Ÿ‘€
Daniel Cook
Daniel Cook

๐Ÿ’ป ๐Ÿ“– โš ๏ธ
Thomas Chia
Thomas Chia

๐Ÿ› ๐Ÿ’ป
Tim Deschryver
Tim Deschryver

๐Ÿ’ป โš ๏ธ ๐Ÿ‘€
Alex Krolick
Alex Krolick

๐Ÿ’ป
Maddi Joyce
Maddi Joyce

๐Ÿ’ป
Peter Kamps
Peter Kamps

๐Ÿ› ๐Ÿ’ป โš ๏ธ
Jonathan Stoye
Jonathan Stoye

๐Ÿ“– ๐Ÿ’ป
Sanghyeon Lee
Sanghyeon Lee

๐Ÿ’ก
Justice Mba
Justice Mba

๐Ÿ’ป ๐Ÿ“– ๐Ÿค”
Wayne Crouch
Wayne Crouch

๐Ÿ’ป
Ben Elliott
Ben Elliott

๐Ÿ’ป
Ruben Costa
Ruben Costa

๐Ÿ’ป
Robert Smith
Robert Smith

๐Ÿ› ๐Ÿค” ๐Ÿ“–
dadamssg
dadamssg

๐Ÿ’ป
Neil Kistner
Neil Kistner

๐Ÿ’ป โš ๏ธ
Ben Chauvette
Ben Chauvette

๐Ÿ’ป
Jeff Baumgardt
Jeff Baumgardt

๐Ÿ’ป ๐Ÿ“–
Matan Kushner
Matan Kushner

๐Ÿ’ป ๐Ÿ“– ๐Ÿค” โš ๏ธ
Alex Wendte
Alex Wendte

๐Ÿ’ป ๐Ÿ“– โš ๏ธ
Tamas Fodor
Tamas Fodor

๐Ÿ“–
Benjamin Eckardt
Benjamin Eckardt

๐Ÿ’ป
Ryan Campbell
Ryan Campbell

๐Ÿ“–
Taylor Briggs
Taylor Briggs

โš ๏ธ
John Gozde
John Gozde

๐Ÿ’ป
C. T. Lin
C. T. Lin

๐Ÿ“–
Terrence Wong
Terrence Wong

๐Ÿ’ป
Soo Jae Hwang
Soo Jae Hwang

๐Ÿ’ป
Royston Shufflebotham
Royston Shufflebotham

๐Ÿ› ๐Ÿ’ป ๐Ÿ“– โš ๏ธ
Vadim Brodsky
Vadim Brodsky

๐Ÿ’ป
Eunjae Lee
Eunjae Lee

๐Ÿ’ป
David Peter
David Peter

๐Ÿ’ป
Shy Alter
Shy Alter

๐Ÿ’ป ๐Ÿ“–
ลukasz Makuch
ลukasz Makuch

๐Ÿ“ฆ
Tyler Haas
Tyler Haas

๐Ÿ’ป โš ๏ธ
Vesa Laakso
Vesa Laakso

๐Ÿ’ป โš ๏ธ
Tulsi Sapkota
Tulsi Sapkota

๐Ÿ’ป
Tiago Nunes
Tiago Nunes

๐Ÿ’ป โš ๏ธ
JaxCavalera
JaxCavalera

๐Ÿ’ป ๐Ÿ‘€
bopfer
bopfer

โš ๏ธ
Jan Pfitzner
Jan Pfitzner

๐Ÿ’ป
David
David

๐Ÿ’ป
Diego Hernandez
Diego Hernandez

๐Ÿ’ป โš ๏ธ
Alex Young
Alex Young

๐Ÿ’ป
Paul Armstrong
Paul Armstrong

๐Ÿ’ป โš ๏ธ
Tamรกs Szabรณ
Tamรกs Szabรณ

๐Ÿ’ป โš ๏ธ
Dylan Piercey
Dylan Piercey

๐Ÿ’ป โš ๏ธ
Michael Lasky
Michael Lasky

๐Ÿ’ป โš ๏ธ ๐Ÿ“–
Sebastian Silbermann
Sebastian Silbermann

๐Ÿ’ป โš ๏ธ ๐Ÿ“– ๐Ÿš‡ ๐Ÿ‘€
Dylan Vann
Dylan Vann

๐Ÿ’ป
Adriร  Fontcuberta
Adriร  Fontcuberta

๐Ÿ’ป โš ๏ธ ๐Ÿ“–
Thomas Lombart
Thomas Lombart

๐Ÿ’ป
Sam Horton
Sam Horton

๐Ÿ’ป โš ๏ธ
Andrew Hill
Andrew Hill

๐Ÿ’ป
Jan Amann
Jan Amann

๐Ÿ’ป โš ๏ธ
Brais Piรฑeiro
Brais Piรฑeiro

๐Ÿ’ป โš ๏ธ
Dominykas Blyลพฤ—
Dominykas Blyลพฤ—

๐Ÿ’ป โš ๏ธ
Olzhas Askar
Olzhas Askar

๐Ÿ’ป โš ๏ธ ๐Ÿ“–
Max Belsky
Max Belsky

๐Ÿ’ป โš ๏ธ
Michael Mantel
Michael Mantel

โš ๏ธ
Tom Nagle
Tom Nagle

๐Ÿ’ป
Westbrook Johnson
Westbrook Johnson

๐Ÿ’ป
Mohammad Aziz
Mohammad Aziz

๐Ÿ’ป โš ๏ธ
seetdev
seetdev

โš ๏ธ ๐Ÿ’ป
Xavier Garcia Buils
Xavier Garcia Buils

๐Ÿ’ป โš ๏ธ
aw-davidson
aw-davidson

๐Ÿ’ป โš ๏ธ
Michaรซl De Boey
Michaรซl De Boey

๐Ÿ’ป
Minh Nguyen
Minh Nguyen

๐Ÿ’ป
Egill Sveinbjรถrnsson
Egill Sveinbjรถrnsson

๐Ÿ’ป
Pavel Pustovalov
Pavel Pustovalov

๐Ÿ“–
Adam Palaniuk
Adam Palaniuk

๐Ÿ’ป โš ๏ธ
Yama-Tomo
Yama-Tomo

๐Ÿ’ป โš ๏ธ
Aaron Pettengill
Aaron Pettengill

๐Ÿ’ป โš ๏ธ
Kate W. Boyd
Kate W. Boyd

๐Ÿ’ป
Rahul Suryakanth
Rahul Suryakanth

๐Ÿ’ป โš ๏ธ
Jamie
Jamie

๐Ÿ’ป โš ๏ธ
Nicolas Stepien
Nicolas Stepien

๐Ÿ’ป
Ken Powers
Ken Powers

๐Ÿ’ป
Michaล‚ Zdunek
Michaล‚ Zdunek

๐Ÿ’ป
Ali Nasserzadeh
Ali Nasserzadeh

๐Ÿ’ป
Darek Kay
Darek Kay

๐Ÿ“– ๐Ÿ’ป โš ๏ธ
Lukas
Lukas

๐Ÿ’ป โš ๏ธ
Tom Crockett
Tom Crockett

๐Ÿ’ป โš ๏ธ
Kevin Brewer
Kevin Brewer

๐Ÿ’ป โš ๏ธ
Ben Monro
Ben Monro

๐Ÿ’ป ๐Ÿค” โš ๏ธ ๐Ÿ“–
Stephan Meijer
Stephan Meijer

๐Ÿค” ๐Ÿ’ป โš ๏ธ
Joรฃo Forja
Joรฃo Forja

๐Ÿ’ป โš ๏ธ
Nick McCurdy
Nick McCurdy

๐Ÿ“– ๐Ÿ’ป โš ๏ธ ๐Ÿ‘€ ๐Ÿš‡
Caleb Meredith
Caleb Meredith

๐Ÿ’ป
Marco Moretti
Marco Moretti

๐Ÿ’ป โš ๏ธ ๐Ÿ‘€
Travis Jefferson
Travis Jefferson

๐Ÿ’ป โš ๏ธ
Maciej Jastrzebski
Maciej Jastrzebski

๐Ÿ›
Geoff Harcourt
Geoff Harcourt

๐Ÿ’ป
Josh Goldberg
Josh Goldberg

๐Ÿ’ป โš ๏ธ
Ken Gregory
Ken Gregory

๐Ÿ’ป โš ๏ธ
Jacob Paris
Jacob Paris

๐Ÿ’ป โš ๏ธ
keiya sasaki
keiya sasaki

๐Ÿ“–
Idan Entin
Idan Entin

๐Ÿ’ป โš ๏ธ
Deniz Susman
Deniz Susman

๐Ÿ’ป
Bianca Del Carretto
Bianca Del Carretto

โš ๏ธ ๐Ÿ’ป
Josh Lalonde
Josh Lalonde

๐Ÿ’ป โš ๏ธ
Ioannis Papadopoulos
Ioannis Papadopoulos

๐Ÿ’ป โš ๏ธ
Maxwell Newlands
Maxwell Newlands

๐Ÿ’ป โš ๏ธ
Jared Luxenberg
Jared Luxenberg

๐Ÿ’ป โš ๏ธ
snizhana
snizhana

๐Ÿ’ป โš ๏ธ
Michael van Engelshoven
Michael van Engelshoven

๐Ÿ‘€
Asher Tuggle
Asher Tuggle

๐Ÿ›
Winter LaMon
Winter LaMon

๐Ÿ’ป โš ๏ธ
Victor Cordova
Victor Cordova

๐Ÿ’ป โš ๏ธ
slowselfip
slowselfip

๐Ÿ›
Dmitry Semigradsky
Dmitry Semigradsky

๐Ÿ’ป
Adam
Adam

๐Ÿ’ป โš ๏ธ
balavishnuvj
balavishnuvj

๐Ÿ’ป
Chris Colborne
Chris Colborne

๐Ÿ’ป
Romain Trotard
Romain Trotard

๐Ÿ’ป
Thomas Marshall
Thomas Marshall

๐Ÿ’ป โš ๏ธ
johnjessewood
johnjessewood

๐Ÿ› ๐Ÿ’ป
Ari Perkkiรถ
Ari Perkkiรถ

๐Ÿ› ๐Ÿ’ป ๐Ÿ“–
Nathan Force
Nathan Force

๐Ÿ’ป
Philipp Fritsche
Philipp Fritsche

๐Ÿ’ป
Renato Alencar
Renato Alencar

๐Ÿ’ป โš ๏ธ
Simen Bekkhus
Simen Bekkhus

๐Ÿ›
Dan Abramov
Dan Abramov

๐Ÿ› ๐Ÿ‘€
Matan Borenkraout
Matan Borenkraout

๐Ÿ’ป
simcha90
simcha90

๐Ÿ’ป
Amit Miran
Amit Miran

๐Ÿš‡
Dominik Lesch
Dominik Lesch

๐Ÿ“–
Gareth Jones
Gareth Jones

๐Ÿ’ป โš ๏ธ
Rayat Rahman
Rayat Rahman

๐Ÿ’ป
Nik Savchenko
Nik Savchenko

๐Ÿ’ป
Kevin Fleischman
Kevin Fleischman

๐Ÿ’ป โš ๏ธ
Beth Hitch
Beth Hitch

๐Ÿ’ป
Jack Laurence
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
Dennis273

๐Ÿ’ป
Jackson Hardaker
Jackson Hardaker

โš ๏ธ
Robin Drexler
Robin Drexler

๐Ÿ’ป
Omer Dolev
Omer Dolev

๐Ÿ’ป
Lirlev48
Lirlev48

๐Ÿ’ป
Tarnay Kรกlmรกn
Tarnay Kรกlmรกn

๐Ÿ’ป
Than Hutchins
Than Hutchins

๐Ÿ’ป
Raphaรซl LEMIEUX
Raphaรซl LEMIEUX

๐Ÿ’ป
Arthur Lauck Vilas Boas
Arthur Lauck Vilas Boas

๐Ÿ“–
Daniel Acuรฑa
Daniel Acuรฑa

๐Ÿ’ป
Craig Morten
Craig Morten

๐Ÿ’ป ๐Ÿ’ฌ
Naor Peled
Naor Peled

๐Ÿ’ป
Julien Wajsberg
Julien Wajsberg

๐Ÿ’ป ๐Ÿ›
Kevin BON
Kevin BON

๐Ÿ’ป ๐Ÿ›
sieem
sieem

๐Ÿ’ป
This project follows the [all-contributors][all-contributors] specification. Contributions of any kind welcome! ## LICENSE [MIT](LICENSE) [npm]: https://www.npmjs.com/ [node]: https://nodejs.org [build-badge]: https://img.shields.io/github/workflow/status/testing-library/dom-testing-library/validate?logo=github&style=flat-square [build]: https://github.com/testing-library/dom-testing-library/actions?query=workflow%3Avalidate [coverage-badge]: https://img.shields.io/codecov/c/github/testing-library/dom-testing-library.svg?style=flat-square [coverage]: https://codecov.io/github/testing-library/dom-testing-library [version-badge]: https://img.shields.io/npm/v/@testing-library/dom.svg?style=flat-square [package]: https://www.npmjs.com/package/@testing-library/dom [downloads-badge]: https://img.shields.io/npm/dm/@testing-library/dom.svg?style=flat-square [npmtrends]: http://www.npmtrends.com/@testing-library/dom [license-badge]: https://img.shields.io/npm/l/@testing-library/dom.svg?style=flat-square [license]: https://github.com/testing-library/dom-testing-library/blob/main/LICENSE [prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square [prs]: http://makeapullrequest.com [coc-badge]: https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square [coc]: https://github.com/testing-library/dom-testing-library/blob/main/CODE_OF_CONDUCT.md [github-watch-badge]: https://img.shields.io/github/watchers/testing-library/dom-testing-library.svg?style=social [github-watch]: https://github.com/testing-library/dom-testing-library/watchers [github-star-badge]: https://img.shields.io/github/stars/testing-library/dom-testing-library.svg?style=social [github-star]: https://github.com/testing-library/dom-testing-library/stargazers [twitter]: https://twitter.com/intent/tweet?text=Check%20out%20dom-testing-library%20by%20%40testing-library%20https%3A%2F%2Fgithub.com%2Ftesting-library%2Fdom-testing-library%20%F0%9F%91%8D [twitter-badge]: https://img.shields.io/twitter/url/https/github.com/testing-library/dom-testing-library.svg?style=social [emojis]: https://github.com/all-contributors/all-contributors#emoji-key [all-contributors]: https://github.com/all-contributors/all-contributors [all-contributors-badge]: https://img.shields.io/github/all-contributors/testing-library/dom-testing-library?color=orange&style=flat-square [set-immediate]: https://developer.mozilla.org/en-US/docs/Web/API/Window/setImmediate [guiding-principle]: https://twitter.com/kentcdodds/status/977018512689455106 [jest]: https://facebook.github.io/jest [discord-badge]: https://img.shields.io/discord/723559267868737556.svg?color=7389D8&labelColor=6A7EC2&logo=discord&logoColor=ffffff&style=flat-square [discord]: https://discord.gg/testing-library