Socket
Socket
Sign inDemoInstall

@testing-library/dom

Package Overview
Dependencies
22
Maintainers
13
Versions
220
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@testing-library/dom

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


Version published
Maintainers
13
Weekly downloads
13,431,983
decreased by-8.85%

Weekly downloads

Package description

What is @testing-library/dom?

The @testing-library/dom package is a lightweight solution for testing DOM nodes (whether they are part of a web browser environment or not) in a way that simulates user actions. It aims to test the functionality of components in a user-centric manner. This library is part of the larger Testing Library ecosystem, which provides tools and utilities to work with React, Vue, Angular, and other frameworks by extending the base functionality provided in @testing-library/dom.

What are @testing-library/dom's main functionalities?

Querying DOM Elements

Allows querying DOM elements using text content, which simulates how users find elements on the page. This is useful for ensuring elements are present and contain the correct content.

const { getByText } = require('@testing-library/dom');
const element = getByText(document.body, 'Hello World');

Firing Events

Simulates user actions by firing events on DOM elements. This is crucial for testing interactive elements like buttons and forms.

const { fireEvent } = require('@testing-library/dom');
fireEvent.click(document.querySelector('button'));

Waiting for Elements

Provides utilities to wait for elements to appear or change, which is useful for testing asynchronous behavior like data fetching or animations.

const { waitFor } = require('@testing-library/dom');
await waitFor(() => getByText(document.body, 'Loaded'));

Other packages similar to @testing-library/dom

Readme

Source

DOM Testing Library

octopus

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

Read the docs | Edit the docs


Build Status Code Coverage version downloads MIT License All Contributors PRs Welcome Code of Conduct Discord

Watch on GitHub Star on GitHub Tweet

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.

Installation

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

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.

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


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

🐛

Rob Caldecott

🐛

Dennis273

💻

Jackson Hardaker

⚠️

Robin Drexler

💻

Omer Dolev

💻

Lirlev48

💻

Tarnay Kálmán

💻

Than Hutchins

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

LICENSE

MIT

Keywords

FAQs

Last updated on 08 Oct 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc