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

Actions Status Renovate badge

eslint-plugin-jest

ESLint plugin for Jest

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
  }
}

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 Enforce consistent test or it keyword fixable-green
expect-expect Enforce assertion to be made in a test body recommended
lowercase-name Disallow capitalized test names fixable-green
no-alias-methods Disallow alias methods style fixable-green
no-commented-out-tests Disallow commented out tests recommended
no-disabled-tests Disallow disabled tests recommended
no-duplicate-hooks Disallow duplicate hooks within a describe block
no-expect-resolves Disallow using expect().resolves
no-export Disallow export from test files recommended
no-focused-tests Disallow focused tests recommended
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-yellow
no-jest-import Disallow importing jest recommended
no-large-snapshots Disallow large snapshots
no-mocks-import Disallow manually importing from __mocks__ recommended
no-standalone-expect Prevents expect statements outside of a test or it block recommended
no-test-callback Using a callback in asynchronous tests recommended fixable-green
no-test-prefixes Disallow using f & x prefixes to define focused/skipped tests recommended fixable-green
no-test-return-statement Disallow explicitly returning from tests
no-truthy-falsy Disallow using toBeTruthy() & toBeFalsy()
no-try-expect Prevent catch assertions in 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 before tests
prefer-inline-snapshots Suggest using toMatchInlineSnapshot() fixable-green
prefer-spy-on Suggest using jest.spyOn() fixable-green
prefer-strict-equal Suggest using toStrictEqual() fixable-green
prefer-to-be-null Suggest using toBeNull() style fixable-green
prefer-to-be-undefined Suggest using toBeUndefined() style fixable-green
prefer-to-contain Suggest using toContain() style fixable-green
prefer-to-have-length Suggest using toHaveLength() style fixable-green
prefer-todo Suggest using test.todo() fixable-green
require-top-level-describe Require a top-level describe block
require-to-throw-message Require that toThrow() and toThrowError includes a message
valid-describe Enforce valid describe() callback recommended
valid-expect-in-promise Enforce having return statement when testing with promises recommended
valid-expect Enforce valid expect() usage recommended
valid-title Enforce valid titles for jest blocks

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.0.4                                ...           latest (6 days ago)
  • 21.3.0-beta.8                                ...           test (2 years ago)

145 Versions

  • 23.0.4                                ...           6 days ago
  • 23.0.3                                ...           12 days ago
  • 23.0.2                                ...           23 days ago
  • 23.0.1                                ...           23 days ago
  • 23.0.0                                ...           24 days ago
  • 22.21.0                                ...           25 days ago
  • 22.20.1                                ...           25 days ago
  • 22.20.0                                ...           a month ago
  • 22.19.0                                ...           a month ago
  • 22.18.0                                ...           a month ago
  • 22.17.0                                ...           2 months ago
  • 22.16.0                                ...           3 months ago
  • 22.15.2                                ...           3 months ago
  • 22.15.1                                ...           3 months ago
  • 22.15.0                                ...           3 months ago
  • 22.14.1                                ...           4 months ago
  • 22.14.0                                ...           4 months ago
  • 22.13.7                                ...           4 months ago
  • 22.13.6                                ...           4 months ago
  • 22.13.5                                ...           4 months ago
  • 22.13.4                                ...           4 months ago
  • 22.13.3                                ...           4 months ago
  • 22.13.2                                ...           4 months ago
  • 22.13.1                                ...           4 months ago
  • 22.13.0                                ...           4 months ago
  • 22.12.0                                ...           4 months ago
  • 22.11.1                                ...           4 months ago
  • 22.11.0                                ...           4 months ago
  • 22.10.0                                ...           4 months ago
  • 22.9.0                                ...           4 months ago
  • 22.8.0                                ...           4 months ago
  • 22.7.2                                ...           5 months ago
  • 22.7.1                                ...           5 months ago
  • 22.7.0                                ...           5 months ago
  • 22.6.4                                ...           6 months ago
  • 22.6.3                                ...           6 months ago
  • 22.6.2                                ...           6 months ago
  • 22.6.1                                ...           6 months ago
  • 22.6.0                                ...           6 months ago
  • 22.5.1                                ...           7 months ago
  • 22.5.0                                ...           7 months ago
  • 22.4.1                                ...           8 months ago
  • 22.4.0                                ...           8 months ago
  • 22.3.2                                ...           8 months ago
  • 22.3.1                                ...           8 months ago
  • 22.3.0                                ...           9 months ago
  • 22.2.2                                ...           10 months ago
  • 22.2.1                                ...           10 months ago
  • 22.2.0                                ...           10 months ago
  • 22.1.3                                ...           10 months ago
  • 22.1.2                                ...           a year ago
  • 22.1.1                                ...           a year ago
  • 22.1.0                                ...           a year ago
  • 22.0.1                                ...           a year ago
  • 22.0.0                                ...           a year ago
  • 21.27.2                                ...           a year ago
  • 21.27.1                                ...           a year ago
  • 21.27.0                                ...           a year ago
  • 21.26.2                                ...           a year ago
  • 21.26.1                                ...           a year ago
  • 21.26.0                                ...           a year ago
  • 21.25.1                                ...           a year ago
  • 21.25.0                                ...           a year ago
  • 21.24.2                                ...           a year ago
  • 21.24.1                                ...           a year ago
  • 21.24.0                                ...           a year ago
  • 21.23.0                                ...           a year ago
  • 21.22.1                                ...           a year ago
  • 21.22.0                                ...           a year ago
  • 21.21.0                                ...           a year ago
  • 21.20.2                                ...           a year ago
  • 21.20.1                                ...           a year ago
  • 21.20.0                                ...           a year ago
  • 21.19.0                                ...           a year ago
  • 21.18.0                                ...           a year ago
  • 21.17.0                                ...           a year ago
  • 21.16.1                                ...           a year ago
  • 21.16.0                                ...           a year ago
  • 21.15.3                                ...           a year ago
  • 21.15.2                                ...           a year 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                                ...           2 years ago
  • 21.3.1                                ...           2 years ago
  • 21.3.0                                ...           2 years ago
  • 21.3.0-beta.8                                ...           2 years ago
  • 21.3.0-beta.7                                ...           2 years ago
  • 21.3.0-beta.6                                ...           2 years ago
  • 21.3.0-beta.5                                ...           2 years ago
  • 21.3.0-beta.4                                ...           2 years ago
  • 21.3.0-beta.3                                ...           2 years ago
  • 21.3.0-alpha.eff7a1cf                                ...           2 years ago
  • 21.3.0-alpha.1e3ee68e                                ...           2 years ago
  • 21.2.0                                ...           2 years ago
  • 21.1.0                                ...           2 years ago
  • 21.0.2                                ...           2 years ago
  • 21.0.0                                ...           2 years ago
  • 21.0.0-beta.1                                ...           2 years ago
  • 21.0.0-alpha.2                                ...           2 years ago
  • 21.0.0-alpha.1                                ...           2 years ago
  • 20.1.0-echo.1                                ...           2 years ago
  • 20.1.0-delta.5                                ...           2 years ago
  • 20.1.0-delta.4                                ...           2 years ago
  • 20.1.0-delta.3                                ...           2 years ago
  • 20.1.0-delta.2                                ...           2 years ago
  • 20.1.0-delta.1                                ...           2 years ago
  • 20.1.0-chi.1                                ...           2 years ago
  • 20.1.0-beta.1                                ...           2 years ago
  • 20.1.0-alpha.3                                ...           2 years ago
  • 20.1.0-alpha.2                                ...           2 years ago
  • 20.1.0-alpha.1                                ...           2 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                                ...           3 years ago
Downloads
Today 46
This Week 8,538
This Month 43,599
Last Day 2,784
Last Week 14,995
Last Month 57,800
Dependencies (1)
Dependents (1019)

Copyright 2014 - 2016 © taobao.org |