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

Build Status Greenkeeper 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). All rules included are:

  • prefer-to-be-null
  • prefer-to-be-undefined
  • prefer-to-contain
  • prefer-to-have-length

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 Recommended Fixable
consistent-test-it Enforce consistent test or it keyword fixable-green
expect-expect Enforce assertion to be made in a test body
lowercase-name Disallow capitalized test names fixable-green
no-alias-methods Disallow alias methods recommended fixable-green
no-disabled-tests Disallow disabled tests recommended
no-commented-out-tests Disallow commented out tests
no-duplicate-hooks Disallow duplicate hooks within a describe block
no-empty-title Disallow empty titles
no-export Disallow export from test files
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-mocks-import Disallow manually importing from __mocks__
no-large-snapshots Disallow large snapshots
no-test-callback Using a callback in asynchronous tests 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
prefer-expect-assertions Suggest using expect.assertions() OR expect.hasAssertions()
prefer-spy-on Suggest using jest.spyOn() fixable-green
prefer-strict-equal Suggest using toStrictEqual() fixable-green
prefer-to-be-null Suggest using toBeNull() fixable-green
prefer-to-be-undefined Suggest using toBeUndefined() fixable-green
prefer-to-contain Suggest using toContain() fixable-green
prefer-to-have-length Suggest using toHaveLength() fixable-green
prefer-inline-snapshots Suggest using toMatchInlineSnapshot() fixable-green
require-tothrow-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
prefer-todo Suggest using test.todo() fixable-green
prefer-called-with Suggest using toBeCalledWith() OR toHaveBeenCalledWith()

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

  • 22.13.6                                ...           latest (8 hours ago)
  • 21.3.0-beta.8                                ...           test (2 years ago)

127 Versions

  • 22.13.6                                ...           8 hours ago
  • 22.13.5                                ...           13 hours ago
  • 22.13.4                                ...           17 hours ago
  • 22.13.3                                ...           18 hours ago
  • 22.13.2                                ...           18 hours ago
  • 22.13.1                                ...           19 hours ago
  • 22.13.0                                ...           2 days ago
  • 22.12.0                                ...           3 days ago
  • 22.11.1                                ...           5 days ago
  • 22.11.0                                ...           5 days ago
  • 22.10.0                                ...           6 days ago
  • 22.9.0                                ...           7 days ago
  • 22.8.0                                ...           8 days ago
  • 22.7.2                                ...           19 days ago
  • 22.7.1                                ...           a month ago
  • 22.7.0                                ...           a month ago
  • 22.6.4                                ...           2 months ago
  • 22.6.3                                ...           2 months ago
  • 22.6.2                                ...           2 months ago
  • 22.6.1                                ...           2 months ago
  • 22.6.0                                ...           2 months ago
  • 22.5.1                                ...           3 months ago
  • 22.5.0                                ...           3 months ago
  • 22.4.1                                ...           4 months ago
  • 22.4.0                                ...           4 months ago
  • 22.3.2                                ...           4 months ago
  • 22.3.1                                ...           4 months ago
  • 22.3.0                                ...           5 months ago
  • 22.2.2                                ...           6 months ago
  • 22.2.1                                ...           6 months ago
  • 22.2.0                                ...           6 months ago
  • 22.1.3                                ...           6 months ago
  • 22.1.2                                ...           8 months ago
  • 22.1.1                                ...           8 months ago
  • 22.1.0                                ...           8 months ago
  • 22.0.1                                ...           8 months ago
  • 22.0.0                                ...           9 months ago
  • 21.27.2                                ...           9 months ago
  • 21.27.1                                ...           9 months ago
  • 21.27.0                                ...           9 months ago
  • 21.26.2                                ...           9 months ago
  • 21.26.1                                ...           9 months ago
  • 21.26.0                                ...           9 months ago
  • 21.25.1                                ...           9 months ago
  • 21.25.0                                ...           9 months ago
  • 21.24.2                                ...           9 months ago
  • 21.24.1                                ...           10 months ago
  • 21.24.0                                ...           10 months ago
  • 21.23.0                                ...           10 months ago
  • 21.22.1                                ...           10 months 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                                ...           a year ago
  • 21.15.0                                ...           a year ago
  • 21.14.1                                ...           a year ago
  • 21.14.0                                ...           a year ago
  • 21.13.0                                ...           a year ago
  • 21.12.3                                ...           a year ago
  • 21.12.2                                ...           a year ago
  • 21.12.1                                ...           a year ago
  • 21.12.0                                ...           a year ago
  • 21.11.0                                ...           a year ago
  • 21.10.0                                ...           a year ago
  • 21.9.0                                ...           a year ago
  • 21.8.0                                ...           a year ago
  • 21.7.1                                ...           a year 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                                ...           2 years ago
  • 20.0.2                                ...           2 years ago
  • 20.0.1                                ...           2 years ago
  • 20.0.0                                ...           2 years ago
  • 19.3.0-alpha.85402254                                ...           2 years ago
  • 19.2.0-alpha.993e64af                                ...           2 years ago
  • 19.1.0-alpha.eed82034                                ...           2 years ago
  • 19.0.1                                ...           2 years ago
  • 19.0.0                                ...           2 years ago
  • 18.5.0-alpha.7da3df39                                ...           2 years ago
  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Downloads
Today 3,056
This Week 6,809
This Month 35,477
Last Day 3,753
Last Week 12,177
Last Month 19,032
Dependencies (1)
Dependents (785)

Copyright 2014 - 2017 © taobao.org |