{"id":19961,"library":"eslint-plugin-testing-library","title":"eslint-plugin-testing-library","description":"An ESLint plugin (v7.16.2) that enforces best practices and catches common mistakes when writing tests with Testing Library (DOM, React, Vue, etc.). Released frequently via semantic-release, it provides over 30 rules to prevent anti-patterns like using wrapper.innerHTML, awaiting async queries incorrectly, or importing from testing-library/dom instead of the framework-specific package. Unlike generic lint rules, it understands Testing Library's query priorities, userEvent vs fireEvent distinction, and the testing file context. Supports ESLint 8, 9, and 10, ships TypeScript types, and offers both ESM and CJS bundles. Requires Node >=18.18.","status":"active","version":"7.16.2","language":"javascript","source_language":"en","source_url":"https://github.com/testing-library/eslint-plugin-testing-library","tags":["javascript","eslint","eslintplugin","eslint-plugin","lint","testing-library","testing","typescript"],"install":[{"cmd":"npm install eslint-plugin-testing-library","lang":"bash","label":"npm"},{"cmd":"yarn add eslint-plugin-testing-library","lang":"bash","label":"yarn"},{"cmd":"pnpm add eslint-plugin-testing-library","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency – required to run as an ESLint plugin","package":"eslint","optional":false}],"imports":[{"note":"Since v7.15.0, the plugin is bundled in both CJS and ESM formats. The default export works for both, but using import is preferred for ESM compatibility.","wrong":"const testingLibrary = require('eslint-plugin-testing-library');","symbol":"plugin (default import)","correct":"import testingLibrary from 'eslint-plugin-testing-library';"},{"note":"configs include presets like 'flat', 'recommended', 'angular', 'react', 'vue'. Use configs['flat/recommended'] for ESLint flat config.","wrong":"const { configs } = require('eslint-plugin-testing-library');","symbol":"configs","correct":"import { configs } from 'eslint-plugin-testing-library';"},{"note":"Rules object contains all rule definitions. Access individual rules like rules['await-async-queries'].","wrong":"const rules = require('eslint-plugin-testing-library').rules;","symbol":"rules","correct":"import { rules } from 'eslint-plugin-testing-library';"}],"quickstart":{"code":"// .eslintrc.js - use overrides to target test files\nmodule.exports = {\n  plugins: ['testing-library'],\n  overrides: [\n    {\n      files: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'],\n      extends: ['plugin:testing-library/react'],\n    },\n  ],\n};\n\n// With ESLint flat config (eslint.config.js)\nimport testingLibrary from 'eslint-plugin-testing-library';\nexport default [\n  { files: ['**/*.test.*', '**/*.spec.*'], ...testingLibrary.configs['flat/react'] },\n];","lang":"javascript","description":"Quick setup using recommended React config, including overrides for test files (legacy) and flat config approach."},"warnings":[{"fix":"Upgrade Node to ^18.18.0 || ^20.9.0 || >=21.1.0, and ESLint to ^8.57.0 || ^9.0.0 || ^10.0.0.","message":"v7 drops support for Node 16 and ESLint 7.","severity":"breaking","affected_versions":">=7.0.0 <8.0.0"},{"fix":"Use the migration guide for v7: https://github.com/testing-library/eslint-plugin-testing-library/blob/main/docs/migration-guides/v7.md","message":"v7 changed rule configurations: some rules moved to different presets and some rules were renamed.","severity":"breaking","affected_versions":">=7.0.0 <8.0.0"},{"fix":"Replace 'testing-library/no-manual-cleanup' with 'testing-library/render-hooks'.","message":"The rule 'no-manual-cleanup' was deprecated in v6 and removed in v7. Use 'render-hooks' instead.","severity":"deprecated","affected_versions":">=6.0.0 <7.0.0"},{"fix":"Use overrides or flat config with file patterns like ['**/*.test.*', '**/*.spec.*'] to restrict the plugin to test files.","message":"The plugin must be configured only for test files (via overrides or flat config file patterns), otherwise it will lint all files and produce warnings for non-test code.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use `testingLibrary.configs['flat/react']` for flat config.","message":"When using flat config (ESLint >= 9), import the plugin's flat configs (e.g. configs['flat/react']) instead of using extends.","severity":"gotcha","affected_versions":">=7.0.0"},{"fix":"Ensure you have a test setup file that calls `userEvent.setup()` and that the rule is configured correctly.","message":"The rule 'prefer-user-event-setup' (added in v7.14.0) requires userEvent to be set up in a setup file; otherwise it will report missing setup.","severity":"gotcha","affected_versions":">=7.14.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-testing-library` in the same project where ESLint is installed.","cause":"The plugin is not installed or is installed globally while ESLint is local, or vice versa.","error":"Error: Failed to load plugin 'testing-library': Cannot find module 'eslint-plugin-testing-library'"},{"fix":"Replace 'no-manual-cleanup' with 'render-hooks' in your ESLint config.","cause":"The rule was deprecated in v6 and removed in v7.","error":"Warning: The 'testing-library/no-manual-cleanup' rule is deprecated. Please use 'testing-library/render-hooks' instead."},{"fix":"Refer to the v7 migration guide: use `testing-library/no-debug` or check the updated preset rules.","cause":"The rule was renamed or moved to a different preset in v7.","error":"Error: ESLint configuration in .eslintrc.js » plugin:testing-library/recommended: Rule 'testing-library/no-debugging-utils' is not found"},{"fix":"Ensure your ESLint config uses a parser that supports the syntax, e.g., `@babel/eslint-parser` or `@typescript-eslint/parser` for TypeScript.","cause":"The test file uses modern JavaScript syntax (e.g., optional chaining) that is not supported by the default parser.","error":"Parsing error: Unexpected token ..."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}