{"id":19802,"library":"eslint-plugin-jest-dom","title":"eslint-plugin-jest-dom","description":"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.","status":"active","version":"5.5.0","language":"javascript","source_language":"en","source_url":"https://github.com/testing-library/eslint-plugin-jest-dom","tags":["javascript","eslint","eslintplugin","eslint-plugin","jest-dom","testing-library","react-testing-library","dom-testing-library","RTL","typescript"],"install":[{"cmd":"npm install eslint-plugin-jest-dom","lang":"bash","label":"npm"},{"cmd":"yarn add eslint-plugin-jest-dom","lang":"bash","label":"yarn"},{"cmd":"pnpm add eslint-plugin-jest-dom","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required at runtime to resolve custom jest-dom matchers; optional since v5.1.0 but needed for full functionality","package":"@testing-library/dom","optional":true},{"reason":"Peer dependency; plugin integrates with ESLint's rule system","package":"eslint","optional":false}],"imports":[{"note":"Plugin object is the default export; no named export for the whole plugin.","wrong":"const plugin = require('eslint-plugin-jest-dom').default;","symbol":"default (plugin object)","correct":"const plugin = require('eslint-plugin-jest-dom'); // CJS\nimport plugin from 'eslint-plugin-jest-dom'; // ESM"},{"note":"Use the flat config key rather than a separate file path. Available since v5.2.0.","wrong":"require('eslint-plugin-jest-dom/flat/recommended')","symbol":"configs['flat/recommended']","correct":"const { configs } = require('eslint-plugin-jest-dom');\nconfigs['flat/recommended']"},{"note":"Rules are grouped under a `rules` object keyed by rule name.","wrong":"const { preferChecked } = require('eslint-plugin-jest-dom');","symbol":"rules","correct":"const { rules } = require('eslint-plugin-jest-dom');\n// Then access rules['prefer-checked'] etc."},{"note":"Only available since v5.5.0; types are exported for the plugin object.","wrong":"","symbol":"TypeScript types for config","correct":"import type { ESLintPluginJestDom } from 'eslint-plugin-jest-dom';"}],"quickstart":{"code":"// Install: npm install --save-dev eslint eslint-plugin-jest-dom @testing-library/dom\n// Then in your .eslintrc.js or eslint.config.js:\n// .eslintrc.js\nmodule.exports = {\n  plugins: ['jest-dom'],\n  extends: ['plugin:jest-dom/recommended'],\n  rules: {\n    'jest-dom/prefer-checked': 'error',\n    'jest-dom/prefer-enabled-disabled': 'error',\n  },\n};\n\n// eslint.config.js (flat config)\nconst jestDom = require('eslint-plugin-jest-dom');\nmodule.exports = [\n  {\n    files: ['**/*.test.js', '**/*.spec.js'],\n    ...jestDom.configs['flat/recommended'],\n    rules: {\n      'jest-dom/prefer-checked': 'error',\n    },\n  },\n];","lang":"javascript","description":"Shows how to install and configure eslint-plugin-jest-dom using both legacy .eslintrc and flat config, enabling recommended rules and custom rules."},"warnings":[{"fix":"Install @testing-library/dom@^8.0.0 || ^9.0.0; or upgrade to v5.1.0+ where it's optional","message":"v5.0.0 requires @testing-library/dom@^8.0.0 || ^9.0.0 as a peer dependency","severity":"breaking","affected_versions":">=5.0.0 <5.1.0"},{"fix":"Watch the changelog and test your config after ESLint updates","message":"Flat config ('flat/recommended') may have subtle differences from legacy config and is subject to breaking changes while ESLint v9 finalizes","severity":"gotcha","affected_versions":">=5.2.0"},{"fix":"Use require('eslint-plugin-jest-dom') without .default","message":"The default export of the plugin object is deprecated in favor of named exports in some contexts; still works but may change","severity":"deprecated","affected_versions":">=5.0.0"},{"fix":"Upgrade to v5.1.1+ which fixes false positives for variable property names","message":"Rule 'prefer-to-have-style' may flag computed property access incorrectly; false positives possible","severity":"gotcha","affected_versions":"<5.1.1"},{"fix":"Upgrade to v5.5.0+ or use @types/eslint-plugin-jest-dom if available","message":"TypeScript types only available since v5.5.0; earlier versions ship no types and will cause type errors if importing","severity":"gotcha","affected_versions":"<5.5.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run 'npm install --save-dev eslint-plugin-jest-dom'","cause":"Plugin is not installed or missing from node_modules","error":"Error: Failed to load plugin 'jest-dom' declared in '.eslintrc.yml': Cannot find module 'eslint-plugin-jest-dom'"},{"fix":"Run 'npm install --save-dev @testing-library/dom@^9.0.0' or upgrade the plugin to v5.1.0+","cause":"Missing peer dependency @testing-library/dom when using v5.0.0","error":"Oops! Something went wrong! :(\nESLint: 8.57.0\n\nError: @testing-library/dom@^9.0.0 is required as a peer dependency"},{"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+","cause":"Using an incorrect import path for flat config before v5.2.0","error":"Error: Cannot find module 'eslint-plugin-jest-dom/flat/recommended'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}