DEV.co
Open-Source Testing · testing-library

jest-dom

jest-dom is a library that extends Jest with custom matchers for testing DOM elements, making test assertions clearer and more readable. It lets you write assertions like `.toBeDisabled()` or `.toHaveClass()` instead of verbose DOM inspection logic.

Source: GitHub — github.com/testing-library/jest-dom
4.6k
GitHub stars
416
Forks
JavaScript
Primary language
MIT
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositorytesting-library/jest-dom
Ownertesting-library
Primary languageJavaScript
LicenseMIT — OSI-approved
Stars4.6k
Forks416
Open issues142
Latest releasev6.9.1 (2025-10-01)
Last updated2026-06-11
Sourcehttps://github.com/testing-library/jest-dom

What jest-dom is

jest-dom provides 28+ custom Jest matchers targeting DOM state queries (attributes, classes, visibility, accessibility roles, form state). It integrates with Jest, Vitest, and Jest-compatible test runners, and works alongside @testing-library packages for query-based assertions.

Quickstart

Get the jest-dom source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/testing-library/jest-dom.gitcd jest-dom# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

React/web app component testing

Validate component DOM output in unit and integration tests using declarative, semantic matchers aligned with testing-library best practices.

Accessibility compliance testing

Assert accessible names, descriptions, roles, error messages, and disabled states to catch a11y regressions early.

Form validation and state testing

Test form element states (checked, disabled, required, valid), display values, and form-wide state with purpose-built matchers.

Implementation considerations

  • Import in a Jest setup file (setupFilesAfterEnv) to extend expect globally; use @testing-library/jest-dom/jest-globals if injectGlobals is false.
  • Requires TypeScript setup: ensure setup file is .ts and included in tsconfig.json if using TypeScript for proper type definitions.
  • Matchers inspect live DOM; use synchronously after queries resolve or after async/act() calls to avoid stale assertions.
  • 142 open issues suggest active development; review issue backlog for known matcher limitations before relying on edge cases.
  • Install eslint-plugin-jest-dom for lint rules that prevent incorrect matcher usage and improve test maintainability.

When to avoid it — and what to weigh

  • Not using Jest or Jest-compatible runner — jest-dom requires Jest or Vitest. If you use Mocha, Jasmine, or other test frameworks without Jest compatibility, this library cannot be used.
  • Server-side only testing — jest-dom targets DOM nodes; it has no value for backend unit tests or server-side rendering validation that doesn't require DOM inspection.
  • E2E browser testing — jest-dom is for unit/integration tests in a Jest environment. For Cypress, Playwright, or Selenium E2E tests, use framework-native assertions instead.
  • Vue 2 or non-standard DOM environments — jest-dom is optimized for React and standard DOM. Vue 2 or custom DOM libraries may have limited matcher relevance.

License & commercial use

MIT License (MIT) – permissive open-source license. Allows unrestricted use, modification, and distribution in commercial and private projects, provided the license header is included.

MIT is a permissive, well-established license suitable for commercial use. No licensing restrictions on bundling or distribution. Verify your own legal compliance for liability; jest-dom is provided as-is.

DEV.co evaluation signals

Editorial assessment — not user reviews. Directional, with an explicit confidence level.

SignalAssessment
MaintenanceActive
DocumentationStrong
License clarityClear
Deployment complexityLow
DEV.co fitStrong
Assessment confidenceHigh
Security considerations

jest-dom is a test utility library with no network I/O, data storage, or authentication. Security posture depends on Jest and the DOM environment. No known CVEs mentioned in provided data. Requires review of dependency chain for production-like test environments.

Alternatives to consider

Chai with chai-dom

Chai assertions library with DOM matchers; use if Mocha or non-Jest test runners are your standard, or for different assertion style.

Vitest native assertions

Vitest's built-in expect has some DOM-like assertions; lighter if you run Vitest and don't need the full jest-dom matcher set.

Testing Library queries only

Use @testing-library queries directly without jest-dom matchers; less readable but avoids a dependency if you prefer manual assertions.

Software development agency

Build on jest-dom with DEV.co software developers

Integrate jest-dom into your Jest test suite to write more readable, maintainable DOM assertions. Get started with a simple npm install and one import.

Talk to DEV.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related on DEV.co

Explore the category and the services that help you build with it.

jest-dom FAQ

Can I use jest-dom with Vitest?
Yes. Import '@testing-library/jest-dom/vitest' in your setup file instead of the default import, add setupFiles to vitest.config.js, and update tsconfig.json types.
Does jest-dom check aria-disabled?
No. toBeDisabled() and toBeEnabled() only check the HTML disabled attribute, not aria-disabled. See issue #144 for design rationale.
What is the difference between toBeEmptyDOMElement and toBeEmpty?
toBeEmptyDOMElement is the current matcher; toBeEmpty is deprecated. Use toBeEmptyDOMElement to check if an element has no visible content.
Do I need eslint-plugin-jest-dom?
No, but it is recommended. The plugin provides auto-fixable lint rules to prevent false positives and ensure you're using the right matchers.

Software developers & web developers for hire

Need help beyond evaluating jest-dom? DEV.co is a software development agency offering software development services and web development for teams of every size. Our software developers and web developers build custom software, web applications, APIs, and open-source testing integrations — and maintain them long-term.

Adopt jest-dom for clearer DOM tests

Integrate jest-dom into your Jest test suite to write more readable, maintainable DOM assertions. Get started with a simple npm install and one import.