eslint-plugin-jest
Eslint rules for Jest
Last updated 5 days ago by simenb .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install eslint-plugin-jest 
SYNC missed versions from official npm registry.

eslint-plugin-jest

ESLint plugin for Jest

Actions Status Renovate badge

Installation

$ yarn add --dev eslint eslint-plugin-jest

Note: If you installed ESLint globally then you must also install eslint-plugin-jest globally.

Usage

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

{
  "plugins": ["jest"]
}

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

{
  "rules": {
    "jest/no-disabled-tests": "warn",
    "jest/no-focused-tests": "error",
    "jest/no-identical-title": "error",
    "jest/prefer-to-have-length": "warn",
    "jest/valid-expect": "error"
  }
}

You can also whitelist the environment variables provided by Jest by doing:

{
  "env": {
    "jest/globals": true
  }
}

The behaviour of some rules (specifically no-deprecated-functions) change depending on the version of jest being used.

This setting is detected automatically based off the version of the jest package installed in node_modules, but it can also be provided explicitly if desired:

{
  "settings": {
    "jest": {
      "version": 26
    }
  }
}

Shareable configurations

Recommended

This plugin exports a recommended configuration that enforces good testing practices.

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

{
  "extends": ["plugin:jest/recommended"]
}

Style

This plugin also exports a configuration named style, which adds some stylistic rules, such as prefer-to-be-null, which enforces usage of toBeNull over toBe(null).

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

{
  "extends": ["plugin:jest/style"]
}

See ESLint documentation for more information about extending configuration files.

All

If you want to enable all rules instead of only some you can do so by adding the all configuration to your .eslintrc config file:

{
  "extends": ["plugin:jest/all"]
}

While the recommended and style configurations only change in major versions the all configuration may change in any release and is thus unsuited for installations requiring long-term consistency.

Rules

Rule Description Configurations Fixable
consistent-test-it Have control over test and it usages fixable
expect-expect Enforce assertion to be made in a test body recommended
lowercase-name Enforce lowercase test names fixable
no-alias-methods Disallow alias methods style fixable
no-commented-out-tests Disallow commented out tests recommended
no-deprecated-functions Disallow use of deprecated functions fixable
no-disabled-tests Disallow disabled tests recommended
no-duplicate-hooks Disallow duplicate setup and teardown hooks
no-export Prevent exporting from test files recommended
no-focused-tests Disallow focused tests recommended fixable
no-hooks Disallow setup and teardown hooks
no-identical-title Disallow identical titles recommended
no-if Disallow conditional logic
no-jasmine-globals Disallow Jasmine globals recommended fixable
no-jest-import Disallow importing Jest recommended
no-large-snapshots disallow large snapshots
no-mocks-import Disallow manually importing from mocks recommended
no-restricted-matchers Disallow specific matchers & modifiers
no-standalone-expect Prevents expects that are outside of an it or test block. recommended
no-test-callback Avoid using a callback in asynchronous tests recommended fixable
no-test-prefixes Use .only and .skip over f and x recommended fixable
no-test-return-statement Disallow explicitly returning from tests
no-try-expect Prefer using toThrow for exception tests recommended
prefer-called-with Suggest using toBeCalledWith() OR toHaveBeenCalledWith()
prefer-expect-assertions Suggest using expect.assertions() OR expect.hasAssertions()
prefer-hooks-on-top Suggest to have all hooks at top level
prefer-spy-on Suggest using jest.spyOn() fixable
prefer-strict-equal Suggest using toStrictEqual() fixable
prefer-to-be-null Suggest using toBeNull() style fixable
prefer-to-be-undefined Suggest using toBeUndefined() style fixable
prefer-to-contain Suggest using toContain() style fixable
prefer-to-have-length Suggest using toHaveLength() style fixable
prefer-todo Suggest using test.todo fixable
require-to-throw-message Require a message for toThrow()
require-top-level-describe Prevents test cases and hooks to be outside of a describe block
valid-describe Enforce valid describe() callback recommended
valid-expect Enforce valid expect() usage recommended
valid-expect-in-promise Enforce having return statement when testing with promises recommended
valid-title Enforce valid titles fixable

Credit

Related Projects

eslint-plugin-jest-formatting

This project aims to provide formatting rules (auto-fixable where possible) to ensure consistency and readability in jest test suites.

https://github.com/dangreenisrael/eslint-plugin-jest-formatting

Current Tags

  • 23.13.2                                ...           latest (5 days ago)
  • 21.3.0-beta.8                                ...           test (3 years ago)

164 Versions

  • 23.13.2                                ...           5 days ago
  • 23.13.1                                ...           14 days ago
  • 23.13.0                                ...           15 days ago
  • 23.12.0                                ...           15 days ago
  • 23.11.0                                ...           19 days ago
  • 23.10.0                                ...           23 days ago
  • 23.9.0                                ...           a month ago
  • 23.8.2                                ...           3 months ago
  • 23.8.1                                ...           3 months ago
  • 23.8.0                                ...           3 months ago
  • 23.7.0                                ...           4 months ago
  • 23.6.0                                ...           5 months ago
  • 23.5.0                                ...           5 months ago
  • 23.4.0                                ...           5 months ago
  • 23.3.0                                ...           5 months ago
  • 23.2.0                                ...           5 months ago
  • 23.1.1                                ...           6 months ago
  • 23.1.0                                ...           6 months ago
  • 23.0.5                                ...           6 months ago
  • 23.0.4                                ...           7 months ago
  • 23.0.3                                ...           7 months ago
  • 23.0.2                                ...           7 months ago
  • 23.0.1                                ...           7 months ago
  • 23.0.0                                ...           7 months ago
  • 22.21.0                                ...           7 months ago
  • 22.20.1                                ...           7 months ago
  • 22.20.0                                ...           7 months ago
  • 22.19.0                                ...           8 months ago
  • 22.18.0                                ...           8 months ago
  • 22.17.0                                ...           9 months ago
  • 22.16.0                                ...           9 months ago
  • 22.15.2                                ...           9 months ago
  • 22.15.1                                ...           10 months ago
  • 22.15.0                                ...           10 months ago
  • 22.14.1                                ...           10 months ago
  • 22.14.0                                ...           10 months ago
  • 22.13.7                                ...           10 months ago
  • 22.13.6                                ...           10 months ago
  • 22.13.5                                ...           10 months ago
  • 22.13.4                                ...           10 months ago
  • 22.13.3                                ...           10 months ago
  • 22.13.2                                ...           10 months ago
  • 22.13.1                                ...           10 months ago
  • 22.13.0                                ...           10 months ago
  • 22.12.0                                ...           10 months ago
  • 22.11.1                                ...           10 months ago
  • 22.11.0                                ...           10 months ago
  • 22.10.0                                ...           10 months ago
  • 22.9.0                                ...           10 months ago
  • 22.8.0                                ...           a year ago
  • 22.7.2                                ...           a year ago
  • 22.7.1                                ...           a year ago
  • 22.7.0                                ...           a year ago
  • 22.6.4                                ...           a year ago
  • 22.6.3                                ...           a year ago
  • 22.6.2                                ...           a year ago
  • 22.6.1                                ...           a year ago
  • 22.6.0                                ...           a year ago
  • 22.5.1                                ...           a year ago
  • 22.5.0                                ...           a year ago
  • 22.4.1                                ...           a year ago
  • 22.4.0                                ...           a year ago
  • 22.3.2                                ...           a year ago
  • 22.3.1                                ...           a year ago
  • 22.3.0                                ...           a year ago
  • 22.2.2                                ...           a year ago
  • 22.2.1                                ...           a year ago
  • 22.2.0                                ...           a year ago
  • 22.1.3                                ...           a year ago
  • 22.1.2                                ...           a year ago
  • 22.1.1                                ...           a year ago
  • 22.1.0                                ...           2 years ago
  • 22.0.1                                ...           2 years ago
  • 22.0.0                                ...           2 years ago
  • 21.27.2                                ...           2 years ago
  • 21.27.1                                ...           2 years ago
  • 21.27.0                                ...           2 years ago
  • 21.26.2                                ...           2 years ago
  • 21.26.1                                ...           2 years ago
  • 21.26.0                                ...           2 years ago
  • 21.25.1                                ...           2 years ago
  • 21.25.0                                ...           2 years ago
  • 21.24.2                                ...           2 years ago
  • 21.24.1                                ...           2 years ago
  • 21.24.0                                ...           2 years ago
  • 21.23.0                                ...           2 years ago
  • 21.22.1                                ...           2 years ago
  • 21.22.0                                ...           2 years ago
  • 21.21.0                                ...           2 years ago
  • 21.20.2                                ...           2 years ago
  • 21.20.1                                ...           2 years ago
  • 21.20.0                                ...           2 years ago
  • 21.19.0                                ...           2 years ago
  • 21.18.0                                ...           2 years ago
  • 21.17.0                                ...           2 years ago
  • 21.16.1                                ...           2 years ago
  • 21.16.0                                ...           2 years ago
  • 21.15.3                                ...           2 years ago
  • 21.15.2                                ...           2 years ago
  • 21.15.1                                ...           2 years ago
  • 21.15.0                                ...           2 years ago
  • 21.14.1                                ...           2 years ago
  • 21.14.0                                ...           2 years ago
  • 21.13.0                                ...           2 years ago
  • 21.12.3                                ...           2 years ago
  • 21.12.2                                ...           2 years ago
  • 21.12.1                                ...           2 years ago
  • 21.12.0                                ...           2 years ago
  • 21.11.0                                ...           2 years ago
  • 21.10.0                                ...           2 years ago
  • 21.9.0                                ...           2 years ago
  • 21.8.0                                ...           2 years ago
  • 21.7.1                                ...           2 years ago
  • 21.7.0                                ...           2 years ago
  • 21.6.2                                ...           2 years ago
  • 21.6.1                                ...           2 years ago
  • 21.6.0                                ...           2 years ago
  • 21.5.0                                ...           2 years ago
  • 21.4.3                                ...           2 years ago
  • 21.4.2                                ...           2 years ago
  • 21.4.1                                ...           2 years ago
  • 21.4.0                                ...           2 years ago
  • 21.3.2                                ...           3 years ago
  • 21.3.1                                ...           3 years ago
  • 21.3.0                                ...           3 years ago
  • 21.3.0-beta.8                                ...           3 years ago
  • 21.3.0-beta.7                                ...           3 years ago
  • 21.3.0-beta.6                                ...           3 years ago
  • 21.3.0-beta.5                                ...           3 years ago
  • 21.3.0-beta.4                                ...           3 years ago
  • 21.3.0-beta.3                                ...           3 years ago
  • 21.3.0-alpha.eff7a1cf                                ...           3 years ago
  • 21.3.0-alpha.1e3ee68e                                ...           3 years ago
  • 21.2.0                                ...           3 years ago
  • 21.1.0                                ...           3 years ago
  • 21.0.2                                ...           3 years ago
  • 21.0.0                                ...           3 years ago
  • 21.0.0-beta.1                                ...           3 years ago
  • 21.0.0-alpha.2                                ...           3 years ago
  • 21.0.0-alpha.1                                ...           3 years ago
  • 20.1.0-echo.1                                ...           3 years ago
  • 20.1.0-delta.5                                ...           3 years ago
  • 20.1.0-delta.4                                ...           3 years ago
  • 20.1.0-delta.3                                ...           3 years ago
  • 20.1.0-delta.2                                ...           3 years ago
  • 20.1.0-delta.1                                ...           3 years ago
  • 20.1.0-chi.1                                ...           3 years ago
  • 20.1.0-beta.1                                ...           3 years ago
  • 20.1.0-alpha.3                                ...           3 years ago
  • 20.1.0-alpha.2                                ...           3 years ago
  • 20.1.0-alpha.1                                ...           3 years ago
  • 20.0.3                                ...           3 years ago
  • 20.0.2                                ...           3 years ago
  • 20.0.1                                ...           3 years ago
  • 20.0.0                                ...           3 years ago
  • 19.3.0-alpha.85402254                                ...           3 years ago
  • 19.2.0-alpha.993e64af                                ...           3 years ago
  • 19.1.0-alpha.eed82034                                ...           3 years ago
  • 19.0.1                                ...           3 years ago
  • 19.0.0                                ...           3 years ago
  • 18.5.0-alpha.7da3df39                                ...           3 years ago
  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           4 years ago
Downloads
Today 53
This Week 53
This Month 53
Last Day 783
Last Week 18,935
Last Month 72,960
Dependencies (1)
Dependents (1379)

Copyright 2014 - 2016 © taobao.org |