DOM Testing Library

Simple, framework-agnostic DOM query utilities that test your UI the way real users interact with it.

Library
npm
v10.4.2
3,338 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 48
Community 72
Maturity 60
Momentum 40

Technical Analysis

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

DOM Testing Library is the framework-agnostic engine behind the entire Testing Library family (React Testing Library, Vue Testing Library, Angular Testing Library, and more). Rather than reaching into component internals or instance state, it queries plain DOM nodes the same way a person would find them: by visible text, label, placeholder, role, or test id. Its guiding principle — “the more your tests resemble the way your software is used, the more confidence they can give you” — pushes teams away from brittle, implementation-coupled tests and toward tests that survive refactors.

At its core sit a small set of composable primitives: getByX/queryByX/findByX/getAllByX query variants generated from shared helpers in query-helpers.ts, an accessibility-first getByRole implementation that mirrors how screen readers see the page, and an async waitFor/waitForElementToBeRemoved pair built on MutationObserver (with a Jest fake-timers-aware code path) for asserting on DOM changes without arbitrary sleeps. A configure() API lets consumers override the test-id attribute, default query behavior, and error formatting, which is exactly the extension point React/Vue/Svelte Testing Library build on top of.

With roughly 70 million weekly npm downloads for this package alone and adoption across nearly every major JS UI framework’s own testing tooling, it has become the de facto standard for behavior-driven, user-centric UI testing in the JavaScript ecosystem.

What You Get

  • A full family of getBy/queryBy/findBy/getAllBy/queryAllBy/findAllBy query variants for text, label text, placeholder text, alt text, title, display value, test id, and ARIA role
  • An accessibility-aware getByRole query that computes implicit ARIA roles and accessible names the way assistive technology does
  • Async waitFor and waitForElementToBeRemoved helpers built on MutationObserver, with correct behavior under both real and Jest fake timers
  • A global configure() API for setting the test-id attribute, default query behavior (e.g. hidden, exact, custom text normalizers), and custom error formatting
  • Built-in query suggestions that nudge you toward higher-priority, more accessible queries (e.g. suggesting getByRole over getByTestId)
  • A prettyDOM/logRoles debugging toolkit that prints a readable DOM snapshot or the accessibility tree straight into failed-test output

Common Use Cases

  • Writing framework-agnostic tests for vanilla JS or web-component UIs without pulling in a component-testing wrapper
  • Serving as the underlying query/assertion engine for React Testing Library, Vue Testing Library, Angular Testing Library, and similar framework adapters
  • Asserting that async UI updates (loading spinners disappearing, content appearing after a fetch) have completed, via waitFor/waitForElementToBeRemoved instead of manual timeouts
  • Auditing and testing accessibility by querying elements the same way assistive technology perceives them, via getByRole and getRoles/logRoles
  • Migrating test suites away from snapshot- or selector-based testing toward behavior-driven tests that don’t break on internal refactors

Under The Hood

Architecture

The library is organized as a small, composable core rather than a monolith: src/query-helpers.ts exposes buildQueries, a factory that takes a single queryAllBy* implementation and mechanically derives the queryBy/getBy/getAllBy/findBy/findAllBy variants (the findBy* variants are produced by wrapping the getter in waitFor from src/wait-for.js), so every query type in src/queries/ (text, role, label-text, placeholder-text, alt-text, title, display-value, test-id) is generated from one shared implementation instead of being hand-duplicated six times over. get-queries-for-element.js binds the whole query set to a given container to power both the top-level screen object and the within() helper, so scoping queries to a subtree is structurally the same operation as querying the whole document. Global behavior (test-id attribute name, error formatting, async timeouts, suggestion opt-in) flows through a single mutable config object in config.ts, read via getConfig() everywhere queries or waitFor need a default — the one clear central dependency in an otherwise flat, function-composition-heavy design.

Tech Stack

The package is written in a mix of plain JavaScript and TypeScript (.ts files hold the newer, more heavily-typed modules like query-helpers.ts, config.ts, and matches.ts), built via kcd-scripts (a shared Babel/Rollup/Jest toolchain wrapper from the same maintainer ecosystem as this project) into CJS, ESM, and UMD bundles declared under main/module/umd:main in package.json. Runtime dependencies are deliberately minimal — aria-query and dom-accessibility-api power the ARIA-role and accessible-name computation behind getByRole, pretty-format and picocolors drive the colorized DOM snapshots used in error messages, and lz-string compresses cached data for repeated snapshot diffing. Type declarations are hand-maintained under types/ rather than machine-generated, giving consumers curated public-facing types independent of internal implementation types.

Code Quality

The project has an extensive Jest test suite under src/__tests__ (dozens of spec files, one roughly per source module, e.g. role.js, wait-for.js, queries.find.js, suggestions.js) plus a parallel src/__node_tests__ suite and split tests/jest.config.dom.js / jest.config.node.js projects to exercise both jsdom and plain Node environments — a testing posture unusually thorough even by this ecosystem’s standards. Linting and formatting are enforced via the shared kcd-scripts ESLint/Prettier config with project-specific rule overrides in package.json, and CI (.github/workflows/validate.yml) runs validation on every push. Error handling favors explicit, purpose-built TestingLibraryElementError instances carrying a pretty-printed DOM snapshot rather than swallowing failures, and naming is consistent throughout (queryAllBy* → queryBy* → getBy* → findBy* derivations follow the same pattern in every query family).

What Makes It Unique

What differentiates this library from ad hoc DOM query helpers is that its queries are deliberately biased toward accessibility semantics rather than raw selectors: getByRole reconstructs the ARIA role and accessible name the way a screen reader would, and the built-in suggestion system actively warns when a test uses a lower-priority query (like a test id) where a higher-priority, more accessible one (like a role or label) would have matched — encoding an opinionated testing philosophy directly into the tool’s runtime behavior rather than leaving it to a style guide. Combined with its role as the shared foundation reused verbatim by nearly every major framework’s own testing-library package, this makes it less a single tool and more a de facto specification for user-centric UI testing across the JS ecosystem.

Used by 87 apps in this directory

Python
100%
Other

Sourcebot

AI Code Assistants · Developer Tools · Search

4,005

A self-hosted, AI-powered code search engine that indexes every repo across GitHub, GitLab, Bitbucket, Gitea, Gerrit, and Azure DevOps, so both engineers and coding agents can search, browse, and ask questions about your codebase from one place.

View details
86
Repo Health
83
Technical
61
Dependency
Built with
Python 100%
Updated 1 weeks ago
TypeScript
47%
Other

Stirling PDF

Digital Signiture · Productivity

94,824

The open-source PDF platform you can run anywhere — edit, convert, sign, and automate PDFs without sending files to external servers.

View details
92
Repo Health
86
Technical
68
Dependency
Built with
TypeScript 47%
Java 44%
Updated 6 days ago
Go
66%
GPL 3.0

Stormkit

Devops · Hosting Control Panel

264

Self-hostable platform for deploying and hosting modern web apps with automated CI/CD, custom domains, and a built-in serverless runtime — a true open-source alternative to Vercel and Netlify.

View details
80
Repo Health
79
Technical
67
Dependency
Built with
Go 66%
TypeScript 31%
Updated 1 weeks ago
TypeScript
89%
Other

strapi

CMS

73,368

Open-source headless CMS that auto-generates REST and GraphQL APIs from your content models, with a fully customizable admin panel you control.

View details
93
Repo Health
84
Technical
63
Dependency
Built with
TypeScript 89%
JavaScript 11%
Updated 1 weeks ago
TypeScript
72%
Apache 2.0

Supabase

Authentication · Databases · Developer Tools

113,827

The open-source Postgres development platform that replaces Firebase with authentication, real-time APIs, edge functions, storage, and vector embeddings — all built on PostgreSQL.

View details
90
Repo Health
91
Technical
62
Dependency
Built with
TypeScript 72%
MDX 26%
Updated 6 days ago
TypeScript
67%
Apache 2.0

tabularis

Databases · Developer Tools

5,270

Open-source desktop SQL workspace with built-in PostgreSQL, MySQL, and SQLite drivers, SQL notebooks, a visual query builder, and a built-in MCP server for AI agents like Claude and Cursor.

View details
84
Repo Health
89
Technical
66
Dependency
Built with
TypeScript 67%
Rust 31%
Updated 6 days ago
TypeScript
99%
Other

Teable

Databases · No Code Platforms

21,920

A no-code PostgreSQL database with spreadsheet UX, real-time collaboration, and native AI agents — built for teams that outgrow Airtable.

View details
78
Repo Health
76
Technical
62
Dependency
Built with
TypeScript 99%
Updated 1 weeks ago
TypeScript
94%
Other

Termix

Devops

15,644

Manage all your servers — SSH terminals, remote desktops, file transfers, and Docker containers — from a single self-hosted browser interface.

View details
84
Repo Health
67
Technical
73
Dependency
Built with
TypeScript 94%
Updated 1 weeks ago
TypeScript
98%
Apache 2.0

Tianji

Analytics · Monitoring

3,119

Replace Google Analytics, UptimeKuma, and Prometheus with one self-hosted platform that tracks websites, monitors uptime, and reports server health.

View details
86
Repo Health
76
Technical
64
Dependency
Built with
TypeScript 98%
Updated 1 weeks ago

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