Registry / testing / eslint-plugin-jest-dom

eslint-plugin-jest-dom

JSON →
library5.5.0jsnpmunverified

ESLint plugin designed to enforce best practices and catch common mistakes when using jest-dom matchers (like toBeChecked, toHaveAttribute) in Testing Library tests. The current stable version is 5.5.0, released in November 2024, with releases every few months. It supports ESLint v6–v9 and provides a recommended configuration as well as flat configs for the new ESLint configuration system. Unlike generic lint rules, this plugin is specifically tailored to the jest-dom API, offering autofixable rules and suggestions to improve test quality. It ships TypeScript definitions and makes @testing-library/dom an optional peer dependency.

npm install eslint-plugin-jest-dom
INSTALL
IMPORT
SIG · ESLINT-PLUGIN-JEST
E
eslint-plugin-jest-dom
testingjavascriptv5.5.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (plugin object)
const plugin = require('eslint-plugin-jest-dom'); // CJS import plugin from 'eslint-plugin-jest-dom'; // ESM
const plugin = require('eslint-plugin-jest-dom').default;
Plugin object is the default export; no named export for the whole plugin.
configs['flat/recommended']
const { configs } = require('eslint-plugin-jest-dom'); configs['flat/recommended']
require('eslint-plugin-jest-dom/flat/recommended')
Use the flat config key rather than a separate file path. Available since v5.2.0.
rules
const { rules } = require('eslint-plugin-jest-dom'); // Then access rules['prefer-checked'] etc.
const { preferChecked } = require('eslint-plugin-jest-dom');
Rules are grouped under a `rules` object keyed by rule name.
TypeScript types for config
import type { ESLintPluginJestDom } from 'eslint-plugin-jest-dom';
Only available since v5.5.0; types are exported for the plugin object.

Shows how to install and configure eslint-plugin-jest-dom using both legacy .eslintrc and flat config, enabling recommended rules and custom rules.

// Install: npm install --save-dev eslint eslint-plugin-jest-dom @testing-library/dom // Then in your .eslintrc.js or eslint.config.js: // .eslintrc.js module.exports = { plugins: ['jest-dom'], extends: ['plugin:jest-dom/recommended'], rules: { 'jest-dom/prefer-checked': 'error', 'jest-dom/prefer-enabled-disabled': 'error', }, }; // eslint.config.js (flat config) const jestDom = require('eslint-plugin-jest-dom'); module.exports = [ { files: ['**/*.test.js', '**/*.spec.js'], ...jestDom.configs['flat/recommended'], rules: { 'jest-dom/prefer-checked': 'error', }, }, ];
Debug
Known issues
breakingv5.0.0 requires @testing-library/dom@^8.0.0 || ^9.0.0 as a peer dependency
fix
Install @testing-library/dom@^8.0.0 || ^9.0.0; or upgrade to v5.1.0+ where it's optional
affects: >=5.0.0 <5.1.0
gotchaFlat config ('flat/recommended') may have subtle differences from legacy config and is subject to breaking changes while ESLint v9 finalizes
fix
Watch the changelog and test your config after ESLint updates
affects: >=5.2.0
deprecatedThe default export of the plugin object is deprecated in favor of named exports in some contexts; still works but may change
fix
Use require('eslint-plugin-jest-dom') without .default
affects: >=5.0.0
gotchaRule 'prefer-to-have-style' may flag computed property access incorrectly; false positives possible
fix
Upgrade to v5.1.1+ which fixes false positives for variable property names
affects: <5.1.1
gotchaTypeScript types only available since v5.5.0; earlier versions ship no types and will cause type errors if importing
fix
Upgrade to v5.5.0+ or use @types/eslint-plugin-jest-dom if available
affects: <5.5.0
Errors
Common errors & fixes
Error: Failed to load plugin 'jest-dom' declared in '.eslintrc.yml': Cannot find module 'eslint-plugin-jest-dom'
Plugin is not installed or missing from node_modules
fix
Run 'npm install --save-dev eslint-plugin-jest-dom'
Oops! Something went wrong! :( ESLint: 8.57.0 Error: @testing-library/dom@^9.0.0 is required as a peer dependency
Missing peer dependency @testing-library/dom when using v5.0.0
fix
Run 'npm install --save-dev @testing-library/dom@^9.0.0' or upgrade the plugin to v5.1.0+
Error: Cannot find module 'eslint-plugin-jest-dom/flat/recommended'
Using an incorrect import path for flat config before v5.2.0
fix
Use the config via the plugin object: const jestDom = require('eslint-plugin-jest-dom'); ...jestDom.configs['flat/recommended']; or upgrade to v5.2.0+
Upgrade
Version history
5.5.0latest on npm
Audit
Dependencies
@testing-library/domoptionalRequired at runtime to resolve custom jest-dom matchers; optional since v5.1.0 but needed for full functionality
eslintrequiredPeer dependency; plugin integrates with ESLint's rule system
Agent activity
4 hits · last 30 days
node
4
Resources
eslint-plugin-jest-dom — npm install eslint-plugin-jest-dom · libregistry