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.

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.

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-focused-tests Disallow focused tests recommended
no-hooks Disallow setup and teardown hooks
no-identical-title Disallow identical titles recommended
no-jasmine-globals Disallow Jasmine globals recommended fixable-yellow
no-jest-import Disallow importing jest recommended
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
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

Credit

Current Tags

  • 22.0.0                                ...           latest (6 days ago)
  • 21.3.0-beta.8                                ...           test (a year ago)

91 Versions

  • 22.0.0                                ...           6 days ago
  • 21.27.2                                ...           7 days ago
  • 21.27.1                                ...           9 days ago
  • 21.27.0                                ...           10 days ago
  • 21.26.2                                ...           18 days ago
  • 21.26.1                                ...           20 days ago
  • 21.26.0                                ...           22 days ago
  • 21.25.1                                ...           a month ago
  • 21.25.0                                ...           a month ago
  • 21.24.2                                ...           a month ago
  • 21.24.1                                ...           a month ago
  • 21.24.0                                ...           a month ago
  • 21.23.0                                ...           a month ago
  • 21.22.1                                ...           2 months ago
  • 21.22.0                                ...           3 months ago
  • 21.21.0                                ...           3 months ago
  • 21.20.2                                ...           3 months ago
  • 21.20.1                                ...           3 months ago
  • 21.20.0                                ...           3 months ago
  • 21.19.0                                ...           3 months ago
  • 21.18.0                                ...           4 months ago
  • 21.17.0                                ...           6 months ago
  • 21.16.1                                ...           6 months ago
  • 21.16.0                                ...           6 months ago
  • 21.15.3                                ...           6 months ago
  • 21.15.2                                ...           6 months ago
  • 21.15.1                                ...           7 months ago
  • 21.15.0                                ...           8 months ago
  • 21.14.1                                ...           8 months ago
  • 21.14.0                                ...           8 months ago
  • 21.13.0                                ...           8 months ago
  • 21.12.3                                ...           8 months ago
  • 21.12.2                                ...           9 months ago
  • 21.12.1                                ...           9 months ago
  • 21.12.0                                ...           9 months ago
  • 21.11.0                                ...           9 months ago
  • 21.10.0                                ...           9 months ago
  • 21.9.0                                ...           9 months ago
  • 21.8.0                                ...           9 months ago
  • 21.7.1                                ...           9 months ago
  • 21.7.0                                ...           10 months ago
  • 21.6.2                                ...           10 months ago
  • 21.6.1                                ...           10 months ago
  • 21.6.0                                ...           10 months ago
  • 21.5.0                                ...           a year ago
  • 21.4.3                                ...           a year ago
  • 21.4.2                                ...           a year ago
  • 21.4.1                                ...           a year ago
  • 21.4.0                                ...           a year ago
  • 21.3.2                                ...           a year ago
  • 21.3.1                                ...           a year ago
  • 21.3.0                                ...           a year ago
  • 21.3.0-beta.8                                ...           a year ago
  • 21.3.0-beta.7                                ...           a year ago
  • 21.3.0-beta.6                                ...           a year ago
  • 21.3.0-beta.5                                ...           a year ago
  • 21.3.0-beta.4                                ...           a year ago
  • 21.3.0-beta.3                                ...           a year ago
  • 21.3.0-alpha.eff7a1cf                                ...           a year ago
  • 21.3.0-alpha.1e3ee68e                                ...           a year ago
  • 21.2.0                                ...           a year ago
  • 21.1.0                                ...           a year ago
  • 21.0.2                                ...           a year ago
  • 21.0.0                                ...           a year ago
  • 21.0.0-beta.1                                ...           a year ago
  • 21.0.0-alpha.2                                ...           a year ago
  • 21.0.0-alpha.1                                ...           a year ago
  • 20.1.0-echo.1                                ...           a year ago
  • 20.1.0-delta.5                                ...           a year ago
  • 20.1.0-delta.4                                ...           a year ago
  • 20.1.0-delta.3                                ...           a year ago
  • 20.1.0-delta.2                                ...           a year ago
  • 20.1.0-delta.1                                ...           a year ago
  • 20.1.0-chi.1                                ...           a year ago
  • 20.1.0-beta.1                                ...           a year ago
  • 20.1.0-alpha.3                                ...           a year ago
  • 20.1.0-alpha.2                                ...           a year ago
  • 20.1.0-alpha.1                                ...           a year ago
  • 20.0.3                                ...           a year ago
  • 20.0.2                                ...           a year 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                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Downloads
Today 98
This Week 931
This Month 3,775
Last Day 413
Last Week 2,057
Last Month 6,387
Dependencies (0)
None
Dependents (439)

Copyright 2014 - 2017 © taobao.org |