jest-dom

Custom Jest matchers for asserting on the state of the DOM in your tests.

Library
npm
v7.0.1
4,600 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
64 /100 Good
Development Activity 36
Maintenance 56
Community 64
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
80 /100 Excellent
Architecture 82
Code Quality 88
Innovation 60
Learning Curve 90

jest-dom is a companion library for Testing Library that adds a set of custom matchers to Jest (and Jest-compatible runners like Vitest) specifically for asserting on DOM nodes. Instead of manually inspecting element.textContent, element.getAttribute(...), or element.classList, you get declarative matchers such as toBeInTheDocument(), toHaveTextContent(), toHaveAttribute(), and toHaveClass() that read like the behavior they verify.

The library is deliberately narrow in scope: it does not render components or query the DOM itself (that’s the job of @testing-library/dom and its framework wrappers) — it only extends expect with matchers that operate on whatever DOM node your test already has a handle to. This keeps it usable across React, Vue, Angular, or plain DOM testing setups, and across both Jest and Vitest via a dedicated /vitest entry point.

Each matcher also produces test-failure output tailored to DOM assertions — printing the actual vs. expected text content, attribute value, or class list with contextual formatting — rather than Jest’s generic object-diff output, which is often unreadable for DOM nodes.

What You Get

  • Presence & visibility matchers - toBeInTheDocument(), toBeVisible(), and toBeEmptyDOMElement() for asserting whether and how an element renders.
  • Form-state matchers - toBeDisabled(), toBeEnabled(), toBeRequired(), toBeInvalid()/toBeValid(), toBeChecked(), and toHaveValue()/toHaveDisplayValue() for form and input assertions.
  • Content & attribute matchers - toHaveTextContent(), toHaveAttribute(), toHaveClass(), toHaveStyle(), and toContainHTML() for verifying rendered output.
  • Accessibility matchers - toHaveAccessibleName(), toHaveAccessibleDescription(), toHaveRole(), and toHaveErrorMessage() for asserting on the accessibility tree.
  • Dedicated entry points - separate /jest-globals and /vitest imports so the matchers register correctly whether you use Jest’s global expect or an explicit one.
  • DOM-aware failure output - custom error formatting that prints readable diffs of text content, attributes, and class lists instead of Jest’s default object serialization.

Common Use Cases

  • Asserting rendered React/Vue/Angular output - after rendering a component with @testing-library/react (or another framework adapter), asserting the resulting DOM node’s text, attributes, or visibility.
  • Form validation tests - checking that inputs are marked required, invalid, disabled, or hold a specific value after user interaction.
  • Accessibility regression tests - asserting accessible names, roles, and ARIA error messages stay correct as markup changes.
  • Migrating off enzyme or manual DOM assertions - replacing hand-rolled element.getAttribute(...) checks with declarative, self-describing matchers.
  • Cross-runner test suites - projects that run the same DOM assertions under both Jest and Vitest via the shared matcher set.

Under The Hood

Architecture jest-dom is structured as one small ES module per matcher (src/to-have-text-content.js, src/to-have-attribute.js, src/to-be-disabled.js, etc.), each exporting a single matcher function with the standard Jest matcher signature (received, ...args) => {pass, message}. src/matchers.js re-exports every matcher plus a generated set of toContainAnyBy*/toContainOneBy* query matchers, and src/index.js simply calls expect.extend(extensions) — the default side-effecting entry point most consumers import once in a test-setup file. Separate src/jest-globals.js and src/vitest.js entry points exist purely to register matchers against a runner-specific expect instead of relying on a Jest global, letting the same matcher implementations work unmodified across runners. Shared plumbing — type-checking, CSS parsing, message formatting — lives centrally in src/utils.js so every matcher throws and formats failures consistently.

Tech Stack The package is plain JavaScript (with a TypeScript-authored types/ tree for consumers) built with Rollup into CommonJS and ESM bundles, exposed through conditional exports map entries for require/import and per-entry-point type declarations. Runtime dependencies are intentionally minimal and focused: @adobe/css-tools for parsing CSS in toHaveStyle, aria-query for role/ARIA lookups, dom-accessibility-api for computing accessible names/descriptions per the WAI-ARIA spec, picocolors for terminal-safe diff coloring, and redent/css.escape for output formatting and selector escaping. @testing-library/dom and vitest are peer dependencies rather than bundled ones, keeping the library agnostic about which runner or query layer a consumer uses.

Code Quality The project has extensive test coverage: nearly every matcher in src/ has a same-named file under src/__tests__/, run through a dual Jest project config (tests/jest.config.dom and tests/jest.config.node) that exercises the matchers against both a real jsdom environment and a plain Node context. Error paths are explicit and typed via dedicated GenericTypeError, HtmlElementTypeError, NodeTypeError, and InvalidCSSError classes in utils.js rather than being swallowed, and every matcher validates its input node before proceeding. Linting and formatting are enforced through kcd-scripts (an opinionated ESLint/Prettier wrapper), and CI runs via GitHub Actions on each push, giving the project consistent, enforced conventions across a very large number of independently-authored matcher files.

API Design The library’s entire public surface is designed to read as natural-language test assertions — expect(element).toBeInTheDocument() versus manually checking document.body.contains(element) — and it deliberately mirrors Jest’s built-in matcher conventions (supporting .not, custom failure messages via this.utils.matcherHint) so it feels native rather than bolted on. Getting started requires a single import in a test-setup file with no configuration, and the conditional exports map means TypeScript users, Jest-globals users, and Vitest users each get a dedicated, correctly-typed entry point without extra setup steps.

Used by 166 apps in this directory

Svelte
53%
MIT

Networking Toolbox

Developer Tools · Security

2,687

The offline-first networking toolbox for sysadmins — 100+ subnet, DNS, DHCP, and TLS utilities that work without internet access.

View details
72
Repo Health
80
Technical
0
Dependency
Built with
Svelte 53%
TypeScript 46%
Updated yesterday
TypeScript
49%
MIT

Nginx Proxy Manager

Developer Tools · Networking · Security

34,361

Manage Nginx reverse proxies and free Let's Encrypt SSL through a beautiful web interface — no Nginx expertise required.

View details
93
Repo Health
77
Technical
72
Dependency
Built with
TypeScript 49%
JavaScript 47%
Updated yesterday
TypeScript
99%
Other

NocoBase

Low Code Platforms · No Code Platforms

24,512

Open-source AI + no-code platform that lets coding agents and people collaborate to build business systems fast on proven infrastructure.

View details
94
Repo Health
81
Technical
63
Dependency
Built with
TypeScript 99%
Updated today
Go
74%
Other

Notifuse

Marketing

2,240

Open-source, self-hosted alternative to Mailchimp, Brevo, and Klaviyo — send newsletters and transactional emails without per-email pricing or vendor lock-in.

View details
81
Repo Health
80
Technical
65
Dependency
Built with
Go 74%
TypeScript 23%
Updated 1 weeks ago
Java
76%
Apache 2.0

Nubase

AI Development · Low Code Platforms

622

Turn AI-written code into real apps — an open-source, self-hostable backend with Database, Auth, Storage, Memory, Functions, Assets, AI Gateway, and cron built for AI coding agents.

View details
71
Repo Health
76
Technical
74
Dependency
Built with
Java 76%
TypeScript 21%
Updated 1 weeks ago
TypeScript
95%
MIT

OmniRoute

AI Agents

74,725

A free, open-source AI gateway connecting Claude Code, Codex, Cursor, Cline, and Copilot to 237 AI providers (90+ free) through one endpoint, with automatic fallback and token-compression to stretch free-tier limits further.

View details
86
Repo Health
70
Technical
70
Dependency
Built with
TypeScript 95%
Updated today
TypeScript
26%
AGPL 3.0

Omnivore

Bookmarks Archiving · Knowledge Management · Note Taking

16,279

Self-hosted read-it-later platform with highlights, newsletters, PDFs, and seamless Obsidian and Logseq integration.

View details
90
Repo Health
74
Technical
65
Dependency
Built with
TypeScript 26%
JavaScript 24%
HTML 20%
Updated yesterday
TypeScript
96%
Apache 2.0

OneUptime

Monitoring

7,719

The complete open-source observability platform that replaces PagerDuty, Datadog, Sentry, and StatusPage with a single self-hostable system.

View details
91
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 96%
Updated today
Python
65%
Other

Onyx

AI Agents · AI Assistants · Knowledge Management

32,380

Self-hostable AI platform with agentic RAG, 50+ connectors, deep research, code execution, and support for every major LLM provider.

View details
92
Repo Health
83
Technical
68
Dependency
Built with
Python 65%
TypeScript 25%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers