Replace verbose DOM assertions in Jest or Vitest tests with readable one-liners like toBeVisible(), toBeDisabled(), and toHaveValue().
Check accessibility in tests by asserting on ARIA roles and accessible names with purpose-built matchers.
Use the companion ESLint plugin to automatically find and fix test files where a simpler jest-dom matcher could replace a generic assertion.
Import once in a Jest or Vitest setup file and all matchers are available globally across every test file.
jest-dom is a JavaScript library that adds extra assertion helpers for testing web page content. When developers write automated tests for websites and web apps, they often need to check things like whether a button is disabled, whether a form field has the right value, whether some text appears on screen, or whether a particular CSS class is applied to an element. The standard Jest testing framework can do some of this, but the checks are verbose and repetitive. jest-dom adds around 30 purpose-built matchers that make these checks shorter and easier to read. For example, instead of writing a multi-step assertion to check whether an input field is disabled, you can write expect(element).toBeDisabled(). Instead of manually inspecting an element's text content with string matching, you can write expect(element).toHaveTextContent('hello'). There are matchers covering visibility, focus state, form values, CSS classes, HTML attributes, ARIA roles and accessibility names, checkbox state, and selection state, among others. The library works with Jest, Vitest, and any other test runner that uses a Jest-compatible assertion interface. You import it once in a setup file and it extends the expect object globally for all your tests. TypeScript types are included, so you get autocomplete in editors that support it. A companion ESLint plugin called eslint-plugin-jest-dom is also available. It checks your test files for cases where you are using a generic assertion when a more specific jest-dom matcher would be clearer, and can fix those automatically. The project is part of the Testing Library family of tools. The full README is longer than what was shown.
← testing-library on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.