eslint-plugin-testing-library
ESLint rules for Testing Library
Last updated 4 years ago by belco .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install eslint-plugin-testing-library 
SYNC missed versions from official npm registry.

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 promises from async queries to be handled 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 promises from fire event methods to be handled vue-badge
consistent-data-testid Ensure data-testid values match a provided regex.
no-await-sync-events Disallow unnecessary await for sync events
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-node-access Disallow direct Node access angular-badge react-badge vue-badge
no-promise-in-fire-event Disallow the use of promises passed to a fireEvent method
no-render-in-setup Disallow the use of render in setup functions
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
no-wait-for-snapshot Ensures no snapshot is generated inside of a waitFor call
no-wait-for-snapshot Ensures no snapshot is generated inside of a waitFor call
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-user-event Suggest using userEvent library instead of fireEvent for simulating user interaction dom-badge angular-badge react-badge vue-badge
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
render-result-naming-convention Enforce a valid naming for return value from render angular-badge react-badge vue-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

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

Josh Kelly

πŸ’»

Alessia Bellisario

πŸ’» ⚠️ πŸ“–

Spencer Miskoviak

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

Giorgio Polvara

πŸ’» ⚠️ πŸ“–

Josh David

πŸ“–

MichaΓ«l De Boey

πŸ’» πŸ“¦ 🚧

Jian Huang

πŸ’» ⚠️ πŸ“–

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

Current Tags

  • 6.0.0-alpha.15                                ...           alpha (a year ago)
  • 7.0.0-beta.1                                ...           beta (7 months ago)
  • 6.3.0                                ...           latest (3 months ago)
  • 4.0.0-alpha.2                                ...           next (4 years ago)

155 Versions

  • 6.3.0                                ...           3 months ago
  • 7.0.0-beta.1                                ...           7 months ago
  • 6.2.2                                ...           7 months ago
  • 6.2.1                                ...           7 months ago
  • 6.2.0                                ...           a year ago
  • 6.1.2                                ...           a year ago
  • 6.1.1                                ...           a year ago
  • 6.1.0                                ...           a year ago
  • 6.0.2                                ...           a year ago
  • 6.0.1                                ...           a year ago
  • 6.0.0                                ...           a year ago
  • 6.0.0-alpha.15                                ...           a year ago
  • 5.11.1                                ...           a year ago
  • 5.11.0                                ...           2 years ago
  • 5.10.3                                ...           2 years ago
  • 5.10.2                                ...           2 years ago
  • 5.10.1                                ...           2 years ago
  • 5.10.0                                ...           2 years ago
  • 6.0.0-alpha.14                                ...           2 years ago
  • 5.9.1                                ...           2 years ago
  • 5.9.0                                ...           2 years ago
  • 5.8.0                                ...           2 years ago
  • 5.7.3                                ...           2 years ago
  • 6.0.0-alpha.13                                ...           2 years ago
  • 6.0.0-alpha.12                                ...           2 years ago
  • 6.0.0-alpha.11                                ...           2 years ago
  • 6.0.0-alpha.10                                ...           2 years ago
  • 6.0.0-alpha.9                                ...           2 years ago
  • 6.0.0-alpha.8                                ...           2 years ago
  • 6.0.0-alpha.7                                ...           2 years ago
  • 6.0.0-alpha.6                                ...           2 years ago
  • 6.0.0-alpha.5                                ...           2 years ago
  • 6.0.0-alpha.4                                ...           2 years ago
  • 5.7.2                                ...           2 years ago
  • 6.0.0-alpha.3                                ...           2 years ago
  • 5.7.1                                ...           2 years ago
  • 5.7.0                                ...           2 years ago
  • 6.0.0-alpha.2                                ...           2 years ago
  • 6.0.0-alpha.1                                ...           2 years ago
  • 5.6.4                                ...           2 years ago
  • 5.6.3                                ...           2 years ago
  • 5.6.2                                ...           2 years ago
  • 5.6.1                                ...           2 years ago
  • 5.6.0                                ...           2 years ago
  • 5.5.1                                ...           2 years ago
  • 5.5.0                                ...           3 years ago
  • 5.4.0                                ...           3 years ago
  • 5.3.1                                ...           3 years ago
  • 5.3.0                                ...           3 years ago
  • 5.2.1                                ...           3 years ago
  • 5.2.0                                ...           3 years ago
  • 5.1.0                                ...           3 years ago
  • 5.0.6                                ...           3 years ago
  • 5.0.5                                ...           3 years ago
  • 5.0.4                                ...           3 years ago
  • 5.0.3                                ...           3 years ago
  • 5.0.2                                ...           3 years ago
  • 5.0.1                                ...           3 years ago
  • 5.0.0                                ...           3 years ago
  • 5.0.0-alpha.10                                ...           3 years ago
  • 5.0.0-alpha.9                                ...           3 years ago
  • 5.0.0-alpha.8                                ...           3 years ago
  • 5.0.0-alpha.7                                ...           3 years ago
  • 5.0.0-alpha.6                                ...           3 years ago
  • 5.0.0-alpha.5                                ...           3 years ago
  • 5.0.0-alpha.4                                ...           3 years ago
  • 5.0.0-alpha.3                                ...           3 years ago
  • 4.12.4                                ...           3 years ago
  • 4.12.3                                ...           3 years ago
  • 4.12.2                                ...           3 years ago
  • 5.0.0-alpha.2                                ...           3 years ago
  • 5.0.0-alpha.1                                ...           3 years ago
  • 4.12.1                                ...           3 years ago
  • 4.12.0                                ...           3 years ago
  • 4.11.0                                ...           3 years ago
  • 4.10.1                                ...           3 years ago
  • 4.10.0                                ...           3 years ago
  • 4.9.3                                ...           3 years ago
  • 4.9.2                                ...           3 years ago
  • 4.9.1                                ...           3 years ago
  • 4.9.0                                ...           3 years ago
  • 4.8.0                                ...           3 years ago
  • 4.7.0                                ...           3 years ago
  • 4.6.0                                ...           3 years ago
  • 4.5.1                                ...           3 years ago
  • 4.5.0                                ...           3 years ago
  • 4.4.0                                ...           4 years ago
  • 4.3.0                                ...           4 years ago
  • 4.2.1                                ...           4 years ago
  • 4.2.0                                ...           4 years ago
  • 4.1.2                                ...           4 years ago
  • 4.1.1                                ...           4 years ago
  • 4.1.0                                ...           4 years ago
  • 4.0.2                                ...           4 years ago
  • 4.0.1                                ...           4 years ago
  • 4.0.0                                ...           4 years ago
  • 4.0.0-beta.6                                ...           4 years ago
  • 4.0.0-beta.5                                ...           4 years ago
  • 4.0.0-beta.4                                ...           4 years ago
  • 4.0.0-beta.3                                ...           4 years ago
  • 4.0.0-beta.2                                ...           4 years ago
  • 4.0.0-beta.1                                ...           4 years ago
  • 4.0.0-alpha.2                                ...           4 years ago
  • 3.10.2                                ...           4 years ago
  • 4.0.0-alpha.1                                ...           4 years ago
  • 4.0.0-alpha.0                                ...           4 years ago
  • 3.10.1                                ...           4 years ago
  • 3.10.0                                ...           4 years ago
  • 3.9.2                                ...           4 years ago
  • 3.9.1                                ...           4 years ago
  • 3.9.0                                ...           4 years ago
  • 3.8.0                                ...           4 years ago
  • 3.7.0                                ...           4 years ago
  • 3.6.0                                ...           4 years ago
  • 3.5.0                                ...           4 years ago
  • 3.4.1                                ...           4 years ago
  • 3.4.0                                ...           4 years ago
  • 3.3.2                                ...           4 years ago
  • 3.3.1                                ...           4 years ago
  • 3.3.0                                ...           4 years ago
  • 3.2.3                                ...           4 years ago
  • 3.2.2                                ...           4 years ago
  • 3.2.1                                ...           4 years ago
  • 3.2.0                                ...           4 years ago
  • 3.1.4                                ...           4 years ago
  • 3.1.3                                ...           4 years ago
  • 3.1.2                                ...           5 years ago
  • 3.1.1                                ...           5 years ago
  • 3.1.0                                ...           5 years ago
  • 3.1.0-beta.3                                ...           5 years ago
  • 3.1.0-beta.2                                ...           5 years ago
  • 3.1.0-beta.1 [deprecated]           ...           5 years ago
  • 3.0.4                                ...           5 years ago
  • 3.0.3                                ...           5 years ago
  • 3.0.2                                ...           5 years ago
  • 3.0.1                                ...           5 years ago
  • 3.0.0                                ...           5 years ago
  • 2.2.3                                ...           5 years ago
  • 2.2.2                                ...           5 years ago
  • 2.2.1                                ...           5 years ago
  • 2.2.0                                ...           5 years ago
  • 2.1.0                                ...           5 years ago
  • 2.0.0                                ...           5 years ago
  • 1.5.0                                ...           5 years ago
  • 1.4.1                                ...           5 years ago
  • 1.4.0                                ...           5 years ago
  • 1.3.4                                ...           5 years ago
  • 1.3.3                                ...           5 years ago
  • 1.3.2                                ...           5 years ago
  • 1.3.1                                ...           5 years ago
  • 1.3.0                                ...           5 years ago
  • 1.2.0                                ...           5 years ago
  • 1.1.1                                ...           5 years ago
  • 0.0.0-development                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Downloads
Total 1
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE