MCPcopy
hub / github.com/testing-library/dom-testing-library

github.com/testing-library/dom-testing-library @v10.4.1 sqlite

repository ↗ · DeepWiki ↗ · release v10.4.1 ↗
185 symbols 549 edges 80 files 16 documented · 9%
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]

TestingJavaScript.com Learn the smart, efficient way to test any JavaScript application.

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 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 💻 ⚠️

Extension points exported contracts — how you extend this code

LogRolesOptions (Interface)
(no doc)
types/role-helpers.d.ts
ByRoleOptions (Interface)
(no doc)
types/queries.d.ts
Queries (Interface)
(no doc)
types/get-queries-for-element.d.ts
Config (Interface)
(no doc)
types/config.d.ts
QueryOptions (Interface)
(no doc)
types/suggestions.d.ts
waitForOptions (Interface)
(no doc)
types/wait-for.d.ts
SelectorMatcherOptions (Interface)
(no doc)
types/query-helpers.d.ts
NormalizerOptions (Interface)
(no doc)
types/matches.d.ts

Core symbols most depended-on inside this repo

getConfig
called by 36
src/config.ts
getSuggestedQuery
called by 34
src/suggestions.js
waitFor
called by 31
src/wait-for.js
configure
called by 30
src/config.ts
queryAllByRole
called by 22
src/queries/role.ts
toString
called by 21
types/suggestions.d.ts
queryAllByText
called by 21
src/queries/text.ts
waitForElementToBeRemoved
called by 16
src/wait-for-element-to-be-removed.js

Shape

Function 163
Interface 14
Class 4
Method 4

Languages

TypeScript100%

Modules by API surface

src/role-helpers.js24 symbols
src/DOMElementFilter.ts14 symbols
types/__tests__/type-tests.ts11 symbols
src/query-helpers.ts11 symbols
src/wait-for.js7 symbols
src/suggestions.js6 symbols
src/queries/role.ts6 symbols
src/queries/label-text.ts6 symbols
src/matches.ts6 symbols
types/config.d.ts5 symbols
src/screen.ts5 symbols
src/label-helpers.ts5 symbols

Dependencies from manifests, versioned

@babel/code-frame7.10.4 · 1×
@babel/runtime7.12.5 · 1×
@testing-library/jest-dom5.11.6 · 1×
@types/aria-query5.0.1 · 1×
aria-query5.3.0 · 1×
browserslist4.21.8 · 1×
caniuse-lite1.0.30001502 · 1×
dom-accessibility-api0.5.9 · 1×
jest-in-case1.0.2 · 1×
jest-snapshot-serializer-ansi1.0.0 · 1×
jest-watch-select-projects2.0.0 · 1×
jsdom20.0.0 · 1×

For agents

$ claude mcp add dom-testing-library \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact