Skip to content

renatoagds/eslint-plugin-testing-library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

eslint-plugin-testing-library

ESLint plugin to follow best practices and anticipate common mistakes when writing tests with Testing Library


Build status Package version MIT License
semantic-release PRs Welcome
Watch on Github Star on Github Tweet

All Contributors

Installation

You'll first need to install ESLint:

$ npm i eslint --save-dev

Next, install eslint-plugin-testing-library:

$ npm install eslint-plugin-testing-library --save-dev

Note: If you installed ESLint globally (using the -g flag) then you must also install eslint-plugin-testing-library globally.

Usage

Add testing-library to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
  "plugins": ["testing-library"]
}

Then configure the rules you want to use under the rules section.

{
  "rules": {
    "testing-library/await-async-query": "error",
    "testing-library/no-await-sync-query": "error",
    "testing-library/no-debug": "warn"
  }
}

Shareable configurations

This plugin exports several recommended configurations that enforce good practices for specific Testing Library packages. You can find more info about enabled rules in the Supported Rules section within the Configurations column.

DOM Testing Library

Enforces recommended rules for DOM Testing Library.

To enable this configuration use the extends property in your .eslintrc config file:

{
  "extends": ["plugin:testing-library/dom"]
}

Angular

Enforces recommended rules for Angular Testing Library.

To enable this configuration use the extends property in your .eslintrc config file:

{
  "extends": ["plugin:testing-library/angular"]
}

React

Enforces recommended rules for React Testing Library.

To enable this configuration use the extends property in your .eslintrc config file:

{
  "extends": ["plugin:testing-library/react"]
}

Vue

Enforces recommended rules for Vue Testing Library.

To enable this configuration use the extends property in your .eslintrc config file:

{
  "extends": ["plugin:testing-library/vue"]
}

Supported Rules

Rule Description Configurations Fixable
await-async-query Enforce async queries to have proper await dom-badge angular-badge react-badge vue-badge
await-async-utils Enforce async utils to be awaited properly dom-badge angular-badge react-badge vue-badge
await-fire-event Enforce async fire event methods to be awaited vue-badge
consistent-data-testid Ensure data-testid values match a provided regex.
no-await-sync-query Disallow unnecessary await for sync queries dom-badge angular-badge react-badge vue-badge
no-container Disallow the use of container methods angular-badge react-badge vue-badge
no-debug Disallow the use of debug angular-badge react-badge vue-badge
no-dom-import Disallow importing from DOM Testing Library angular-badge react-badge vue-badge fixable-badge
no-manual-cleanup Disallow the use of cleanup
no-multiple-assertions-wait-for Disallow the use of multiple expect inside waitFor
no-promise-in-fire-event Disallow the use of promises passed to a fireEvent method
no-side-effects-wait-for Disallow the use of side effects inside waitFor
no-wait-for-empty-callback Disallow empty callbacks for waitFor and waitForElementToBeRemoved dom-badge angular-badge react-badge vue-badge
prefer-explicit-assert Suggest using explicit assertions rather than just getBy* queries
prefer-find-by Suggest using findBy* methods instead of the waitFor + getBy queries dom-badge angular-badge react-badge vue-badge fixable-badge
prefer-presence-queries Enforce specific queries when checking element is present or not
prefer-screen-queries Suggest using screen while using queries dom-badge angular-badge react-badge vue-badge
prefer-wait-for Use waitFor instead of deprecated wait methods fixable-badge

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Mario BeltrΓ‘n AlarcΓ³n

πŸ’» πŸ“– πŸ‘€ ⚠️ πŸš‡ πŸ›

Thomas Lombart

πŸ’» πŸ“– πŸ‘€ ⚠️ πŸš‡

Ben Monro

πŸ’» πŸ“– ⚠️

Nicola Molinari

πŸ’» ⚠️ πŸ“– πŸ‘€

AarΓ³n GarcΓ­a HervΓ‘s

πŸ“–

Matej Ε nuderl

πŸ€” πŸ“–

AdriΓ  Fontcuberta

πŸ’» ⚠️

Jon Aldinger

πŸ“–

Thomas Knickman

πŸ’» πŸ“– ⚠️

Kevin Sullivan

πŸ“–

Jakub JastrzΔ™bski

πŸ’» πŸ“– ⚠️

Nikolay Stoynov

πŸ“–

marudor

πŸ’» ⚠️

Tim Deschryver

πŸ’» πŸ“– πŸ€” πŸ‘€ ⚠️ πŸ› πŸš‡ πŸ“¦

Tobias Deekens

πŸ›

Victor Cordova

πŸ’» ⚠️ πŸ›

Dmitry Lobanov

πŸ’» ⚠️

Kent C. Dodds

πŸ›

Gonzalo D'Elia

πŸ’» ⚠️ πŸ“– πŸ‘€

Jeff Rifwald

πŸ“–

Leandro Lourenci

πŸ› πŸ’» ⚠️

Miguel Erja GonzΓ‘lez

πŸ›

Pavel Pustovalov

πŸ›

Jacob Parish

πŸ› πŸ’» ⚠️

Nick McCurdy

πŸ€” πŸ’» πŸ‘€

Stefan Cameron

πŸ›

Mateus Felix

πŸ’» ⚠️ πŸ“–

Renato Augusto Gama dos Santos

πŸ€” πŸ’» πŸ“– ⚠️

This project follows the all-contributors specification. Contributions of any kind welcome!

About

ESLint plugin for Testing Library

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 99.7%
  • JavaScript 0.3%