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.
npm install eslint-plugin-testing-libraryVerified import paths — ran on the pinned version, not inferred.
Quick setup using recommended React config, including overrides for test files (legacy) and flat config approach.
Upgrade Node to ^18.18.0 || ^20.9.0 || >=21.1.0, and ESLint to ^8.57.0 || ^9.0.0 || ^10.0.0.
Use the migration guide for v7: https://github.com/testing-library/eslint-plugin-testing-library/blob/main/docs/migration-guides/v7.md
Replace 'testing-library/no-manual-cleanup' with 'testing-library/render-hooks'.
Use overrides or flat config with file patterns like ['**/*.test.*', '**/*.spec.*'] to restrict the plugin to test files.
Use `testingLibrary.configs['flat/react']` for flat config.
Ensure you have a test setup file that calls `userEvent.setup()` and that the rule is configured correctly.
Run `npm install --save-dev eslint-plugin-testing-library` in the same project where ESLint is installed.
Replace 'no-manual-cleanup' with 'render-hooks' in your ESLint config.
Refer to the v7 migration guide: use `testing-library/no-debug` or check the updated preset rules.
Ensure your ESLint config uses a parser that supports the syntax, e.g., `@babel/eslint-parser` or `@typescript-eslint/parser` for TypeScript.