@testing-library/dom

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

Stats

StarsIssuesVersionUpdatedCreatedSize
@testing-library/dom
2,772678.11.210 days ago3 years agoMinified + gzip package size for @testing-library/dom in KB

Readme

DOM Testing Library

octopus

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

Read the docs | Edit the 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] [![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]

Table of Contents

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 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

Documentation

Read the docs (and discover framework and tool-specific implementations) at testing-library.com

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

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

Greg Bergรฉ

๐Ÿค”

Ryan Castner

๐Ÿ“–

Daniel Sandiego

๐Ÿ’ป

Paweล‚ Mikoล‚ajczyk

๐Ÿ’ป

Alejandro ร‘รกรฑez Ortiz

๐Ÿ“–

Matt Parrish

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

Justin Hall

๐Ÿ“ฆ

Anto Aravinth

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

Jonah Moses

๐Ÿ“–

ลukasz Gandecki

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

Ivan Babak

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

Jesse Day

๐Ÿ’ป

Ernesto Garcรญa

๐Ÿ’ฌ ๐Ÿ’ป ๐Ÿ“–

Josef Maxx Blake

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

Alex Cook

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

Daniel Cook

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

Thomas Chia

๐Ÿ› ๐Ÿ’ป

Tim Deschryver

๐Ÿ’ป โš ๏ธ

Alex Krolick

๐Ÿ’ป

Maddi Joyce

๐Ÿ’ป

Peter Kamps

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

Jonathan Stoye

๐Ÿ“– ๐Ÿ’ป

Sanghyeon Lee

๐Ÿ’ก

Justice Mba

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

Wayne Crouch

๐Ÿ’ป

Ben Elliott

๐Ÿ’ป

Ruben Costa

๐Ÿ’ป

Robert Smith

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

dadamssg

๐Ÿ’ป

Neil Kistner

๐Ÿ’ป โš ๏ธ

Ben Chauvette

๐Ÿ’ป

Jeff Baumgardt

๐Ÿ’ป ๐Ÿ“–

Matan Kushner

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

Alex Wendte

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

Tamas Fodor

๐Ÿ“–

Benjamin Eckardt

๐Ÿ’ป

Ryan Campbell

๐Ÿ“–

Taylor Briggs

โš ๏ธ

John Gozde

๐Ÿ’ป

C. T. Lin

๐Ÿ“–

Terrence Wong

๐Ÿ’ป

Soo Jae Hwang

๐Ÿ’ป

Royston Shufflebotham

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

Vadim Brodsky

๐Ÿ’ป

Eunjae Lee

๐Ÿ’ป

David Peter

๐Ÿ’ป

Shy Alter

๐Ÿ’ป ๐Ÿ“–

ลukasz Makuch

๐Ÿ“ฆ

Tyler Haas

๐Ÿ’ป โš ๏ธ

Vesa Laakso

๐Ÿ’ป โš ๏ธ

Tulsi Sapkota

๐Ÿ’ป

Tiago Nunes

๐Ÿ’ป โš ๏ธ

JaxCavalera

๐Ÿ’ป ๐Ÿ‘€

bopfer

โš ๏ธ

Jan Pfitzner

๐Ÿ’ป

David

๐Ÿ’ป

Diego Hernandez

๐Ÿ’ป โš ๏ธ

Alex Young

๐Ÿ’ป

Paul Armstrong

๐Ÿ’ป โš ๏ธ

Tamรกs Szabรณ

๐Ÿ’ป โš ๏ธ

Dylan Piercey

๐Ÿ’ป โš ๏ธ

Michael Lasky

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

Sebastian Silbermann

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

Dylan Vann

๐Ÿ’ป

Adriร  Fontcuberta

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

Thomas Lombart

๐Ÿ’ป

Sam Horton

๐Ÿ’ป โš ๏ธ

Andrew Hill

๐Ÿ’ป

Jan Amann

๐Ÿ’ป โš ๏ธ

Brais Piรฑeiro

๐Ÿ’ป โš ๏ธ

Dominykas Blyลพฤ—

๐Ÿ’ป โš ๏ธ

Olzhas Askar

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

Max Belsky

๐Ÿ’ป โš ๏ธ

Michael Mantel

โš ๏ธ

Tom Nagle

๐Ÿ’ป

Westbrook Johnson

๐Ÿ’ป

Mohammad Aziz

๐Ÿ’ป โš ๏ธ

seetdev

โš ๏ธ ๐Ÿ’ป

Xavier Garcia Buils

๐Ÿ’ป โš ๏ธ

aw-davidson

๐Ÿ’ป โš ๏ธ

Michaรซl De Boey

๐Ÿ’ป

Minh Nguyen

๐Ÿ’ป

Egill Sveinbjรถrnsson

๐Ÿ’ป

Pavel Pustovalov

๐Ÿ“–

Adam Palaniuk

๐Ÿ’ป โš ๏ธ

Yama-Tomo

๐Ÿ’ป โš ๏ธ

Aaron Pettengill

๐Ÿ’ป โš ๏ธ

Kate W. Boyd

๐Ÿ’ป

Rahul Suryakanth

๐Ÿ’ป โš ๏ธ

Jamie

๐Ÿ’ป โš ๏ธ

Nicolas Stepien

๐Ÿ’ป

Ken Powers

๐Ÿ’ป

Michaล‚ Zdunek

๐Ÿ’ป

Ali Nasserzadeh

๐Ÿ’ป

Darek Kay

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

Lukas

๐Ÿ’ป โš ๏ธ

Tom Crockett

๐Ÿ’ป โš ๏ธ

Kevin Brewer

๐Ÿ’ป โš ๏ธ

Ben Monro

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

Stephan Meijer

๐Ÿค” ๐Ÿ’ป โš ๏ธ

Joรฃo Forja

๐Ÿ’ป โš ๏ธ

Nick McCurdy

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

Caleb Meredith

๐Ÿ’ป

Marco Moretti

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

Travis Jefferson

๐Ÿ’ป โš ๏ธ

Maciej Jastrzebski

๐Ÿ›

Geoff Harcourt

๐Ÿ’ป

Josh Goldberg

๐Ÿ’ป โš ๏ธ

Ken Gregory

๐Ÿ’ป โš ๏ธ

Jacob Paris

๐Ÿ’ป โš ๏ธ

keiya sasaki

๐Ÿ“–

Idan Entin

๐Ÿ’ป โš ๏ธ

Deniz Susman

๐Ÿ’ป

Bianca Del Carretto

โš ๏ธ ๐Ÿ’ป

Josh Lalonde

๐Ÿ’ป โš ๏ธ

Ioannis Papadopoulos

๐Ÿ’ป โš ๏ธ

Maxwell Newlands

๐Ÿ’ป โš ๏ธ

Jared Luxenberg

๐Ÿ’ป โš ๏ธ

snizhana

๐Ÿ’ป โš ๏ธ

Michael van Engelshoven

๐Ÿ‘€

Asher Tuggle

๐Ÿ›

Winter LaMon

๐Ÿ’ป โš ๏ธ

Victor Cordova

๐Ÿ’ป โš ๏ธ

slowselfip

๐Ÿ›

Dmitry Semigradsky

๐Ÿ’ป

Adam

๐Ÿ’ป โš ๏ธ

balavishnuvj

๐Ÿ’ป

Chris Colborne

๐Ÿ’ป

Romain Trotard

๐Ÿ’ป

Thomas Marshall

๐Ÿ’ป โš ๏ธ

johnjessewood

๐Ÿ› ๐Ÿ’ป

Ari Perkkiรถ

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

Nathan Force

๐Ÿ’ป

Philipp Fritsche

๐Ÿ’ป

Renato Alencar

๐Ÿ’ป โš ๏ธ

Simen Bekkhus

๐Ÿ›

Dan Abramov

๐Ÿ› ๐Ÿ‘€

Matan Borenkraout

๐Ÿ’ป

simcha90

๐Ÿ’ป

Amit Miran

๐Ÿš‡

Dominik Lesch

๐Ÿ“–

Gareth Jones

๐Ÿ’ป โš ๏ธ

Rayat Rahman

๐Ÿ’ป

Nik Savchenko

๐Ÿ’ป

Kevin Fleischman

๐Ÿ’ป โš ๏ธ

Beth Hitch

๐Ÿ’ป

Jack Laurence

๐Ÿ’ป

SantoJambit

๐Ÿ’ป

Yashu Mittal

๐Ÿ“–

Ian VanSchooten

๐Ÿ’ป

Vanya Prokopovich

๐Ÿ›

James Nail

๐Ÿ›

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.