🐙 Simple and complete DOM testing utilities that encourage good testing practices.
Installations
npm install @testing-library/dom
Developer
Developer Guide
Module System
CommonJS
Min. Node Version
>=18
Typescript Support
Yes
Node Version
18.20.4
NPM Version
10.7.0
Statistics
3,274 Stars
654 Commits
467 Forks
32 Watching
3 Branches
196 Contributors
Updated on 26 Nov 2024
Bundle Size
181.30 kB
Minified
32.65 kB
Minified + Gzipped
Languages
JavaScript (77.41%)
TypeScript (22.59%)
Total Downloads
Cumulative downloads
Total Downloads
2,156,827,072
Last day
-7.4%
3,110,387
Compared to previous day
Last week
1.7%
17,431,496
Compared to previous week
Last month
6.7%
73,772,973
Compared to previous month
Last year
26.1%
766,845,044
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
DOM Testing Library
Simple and complete DOM testing utilities that encourage good testing practices.
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
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:
- 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.
Contributors
Thanks goes to these people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
LICENSE
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
GitHub workflow tokens follow principle of least privilege
Details
- Info: jobLevel 'contents' permission set to 'read': .github/workflows/validate.yml:25
- Warn: jobLevel 'contents' permission set to 'write': .github/workflows/validate.yml:67
- Info: found token with 'none' permissions: .github/workflows/validate.yml:1
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
0 commit(s) and 10 issue activity found in the last 90 days -- score normalized to 8
Reason
Found 16/22 approved changesets -- score normalized to 7
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/accessibility-alt-text.yml:28: update your workflow using https://app.stepsecurity.io/secureworkflow/testing-library/dom-testing-library/accessibility-alt-text.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/validate.yml:77: update your workflow using https://app.stepsecurity.io/secureworkflow/testing-library/dom-testing-library/validate.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/validate.yml:80: update your workflow using https://app.stepsecurity.io/secureworkflow/testing-library/dom-testing-library/validate.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/validate.yml:85: update your workflow using https://app.stepsecurity.io/secureworkflow/testing-library/dom-testing-library/validate.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/validate.yml:93: update your workflow using https://app.stepsecurity.io/secureworkflow/testing-library/dom-testing-library/validate.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/validate.yml:36: update your workflow using https://app.stepsecurity.io/secureworkflow/testing-library/dom-testing-library/validate.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/validate.yml:42: update your workflow using https://app.stepsecurity.io/secureworkflow/testing-library/dom-testing-library/validate.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/validate.yml:47: update your workflow using https://app.stepsecurity.io/secureworkflow/testing-library/dom-testing-library/validate.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/validate.yml:59: update your workflow using https://app.stepsecurity.io/secureworkflow/testing-library/dom-testing-library/validate.yml/main?enable=pin
- Info: 0 out of 5 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 4 third-party GitHubAction dependencies pinned
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 30 are checked with a SAST tool
Score
6.4
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to @testing-library/dom
rescript-dom-testing-library
ReScript bindings for @testing-library/dom
@testing-library/jest-dom
Custom jest matchers to test the state of the DOM
@testing-library/react
Simple and complete React DOM testing utilities that encourage good testing practices.
eslint-plugin-jest-dom
ESLint plugin to follow best practices and anticipate common mistakes when writing tests with jest-dom