Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@testing-library/dom
Advanced tools
Simple and complete DOM testing utilities that encourage good testing practices.
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.
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'));
Enzyme is a JavaScript Testing utility for React that makes it easier to test your React Components' output. It allows you to manipulate, traverse, and in some ways simulate runtime given the output. Enzyme's API is more focused on React specifically compared to @testing-library/dom which is framework-agnostic.
Cypress is a front end testing tool built for the modern web. It is built on a new architecture and runs in the same run-loop as the application being tested. Cypress also acts as an end-to-end testing framework, unlike @testing-library/dom which is more focused on unit and integration tests.
Selenium WebDriver is a browser automation library. Most often used for testing web-applications, Selenium allows you to perform tasks as if you were the user of the application. It's more comprehensive for end-to-end testing across different browsers compared to @testing-library/dom which is more lightweight and focused on simulating user actions in a testing environment.
Simple and complete DOM testing utilities that encourage good testing practices.
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.
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.
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
Read the docs (and discover framework and tool-specific implementations) at testing-library.com
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:
At the end of the day, what we want is for this library to be pretty light-weight, simple, and understandable.
Thanks goes to these people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
FAQs
Simple and complete DOM testing utilities that encourage good testing practices.
The npm package @testing-library/dom receives a total of 13,035,976 weekly downloads. As such, @testing-library/dom popularity was classified as popular.
We found that @testing-library/dom demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 15 open source maintainers collaborating on the project.
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.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.