Gathering detailed insights and metrics for eslint-plugin-jest
The total size of the npm registry is estimated to be over 4 terabytes. This includes all the packages, versions, and metadata stored in the registry.
Gathering detailed insights and metrics for eslint-plugin-jest
The total size of the npm registry is estimated to be over 4 terabytes. This includes all the packages, versions, and metadata stored in the registry.
npm install eslint-plugin-jest
60.3
Supply Chain
60.3
Quality
91.7
Maintenance
100
Vulnerability
96.1
License
1,135 Stars
1,428 Commits
236 Forks
12 Watching
5 Branches
140 Contributors
Updated on 18 Nov 2024
Minified
Minified + Gzipped
TypeScript (98.06%)
JavaScript (1.94%)
Shell (0.01%)
Cumulative downloads
Total Downloads
Last day
11.8%
2,399,522
Compared to previous day
Last week
7.3%
12,824,627
Compared to previous week
Last month
7.6%
51,805,048
Compared to previous month
Last year
11.5%
541,403,190
Compared to previous year
1
3
43
1yarn add --dev eslint eslint-plugin-jest
Note: If you installed ESLint globally then you must also install
eslint-plugin-jest
globally.
If you're using flat configuration:
With flat configuration, just import the plugin and away you go:
1const pluginJest = require('eslint-plugin-jest'); 2 3module.exports = [ 4 { 5 // update this to match your test files 6 files: ['**/*.spec.js', '**/*.test.js'], 7 plugins: { jest: pluginJest }, 8 languageOptions: { 9 globals: pluginJest.environments.globals.globals, 10 }, 11 rules: { 12 'jest/no-disabled-tests': 'warn', 13 'jest/no-focused-tests': 'error', 14 'jest/no-identical-title': 'error', 15 'jest/prefer-to-have-length': 'warn', 16 'jest/valid-expect': 'error', 17 }, 18 }, 19];
With legacy configuration, add jest
to the plugins section of your .eslintrc
configuration file. You can omit the eslint-plugin-
prefix:
1{ 2 "plugins": ["jest"], 3 "env": { 4 "jest/globals": true 5 }, 6 "rules": { 7 "jest/no-disabled-tests": "warn", 8 "jest/no-focused-tests": "error", 9 "jest/no-identical-title": "error", 10 "jest/prefer-to-have-length": "warn", 11 "jest/valid-expect": "error" 12 } 13}
[!NOTE]
You only need to explicitly include our globals if you're not using one of our shared configs
You can tell this plugin about any global Jests you have aliased using the
globalAliases
setting:
1{ 2 "settings": { 3 "jest": { 4 "globalAliases": { 5 "describe": ["context"], 6 "fdescribe": ["fcontext"], 7 "xdescribe": ["xcontext"] 8 } 9 } 10 } 11}
@jest/globals
You can tell this plugin to treat a different package as the source of Jest
globals using the globalPackage
setting:
1{ 2 "settings": { 3 "jest": { 4 "globalPackage": "bun:test" 5 } 6 } 7}
[!WARNING]
While this can be used to apply rules when using alternative testing libraries and frameworks like
bun
,vitest
andnode
, there's no guarantee the semantics this plugin assumes will hold outside of Jest
The rules provided by this plugin assume that the files they are checking are test-related. This means it's generally not suitable to include them in your top-level configuration as that applies to all files being linted which can include source files.
For .eslintrc
configs you can use
overrides
to have ESLint apply additional rules to specific files:
1{ 2 "extends": ["eslint:recommended"], 3 "overrides": [ 4 { 5 "files": ["test/**"], 6 "plugins": ["jest"], 7 "extends": ["plugin:jest/recommended"], 8 "rules": { "jest/prefer-expect-assertions": "off" } 9 } 10 ], 11 "rules": { 12 "indent": ["error", 2] 13 } 14}
For eslint.config.js
you can use
files
and ignores
:
1const jest = require('eslint-plugin-jest'); 2 3module.exports = [ 4 ...require('@eslint/js').configs.recommended, 5 { 6 files: ['test/**'], 7 ...jest.configs['flat/recommended'], 8 rules: { 9 ...jest.configs['flat/recommended'].rules, 10 'jest/prefer-expect-assertions': 'off', 11 }, 12 }, 13 // you can also configure jest rules in other objects, so long as some of the `files` match 14 { 15 files: ['test/**'], 16 rules: { 'jest/prefer-expect-assertions': 'off' }, 17 }, 18];
version
settingThe behaviour of some rules (specifically no-deprecated-functions
) change
depending on the version of Jest being used.
By default, this plugin will attempt to determine to locate Jest using
require.resolve
, meaning it will start looking in the closest node_modules
folder to the file being linted and work its way up.
Since we cache the automatically determined version, if you're linting sub-folders that have different versions of Jest, you may find that the wrong version of Jest is considered when linting. You can work around this by providing the Jest version explicitly in nested ESLint configs:
1{ 2 "settings": { 3 "jest": { 4 "version": 27 5 } 6 } 7}
To avoid hard-coding a number, you can also fetch it from the installed version
of Jest if you use a JavaScript config file such as .eslintrc.js
:
1module.exports = { 2 settings: { 3 jest: { 4 version: require('jest/package.json').version, 5 }, 6 }, 7};
[!NOTE]
eslint.config.js
compatible versions of configs are available prefixed withflat/
and may be subject to small breaking changes while ESLint v9 is being finalized.
This plugin exports a recommended configuration that enforces good testing practices.
To enable this configuration with .eslintrc
, use the extends
property:
1{ 2 "extends": ["plugin:jest/recommended"] 3}
To enable this configuration with eslint.config.js
, use
jest.configs['flat/recommended']
:
1const jest = require('eslint-plugin-jest'); 2 3module.exports = [ 4 { 5 files: [ 6 /* glob matching your test files */ 7 ], 8 ...jest.configs['flat/recommended'], 9 }, 10];
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:
1{ 2 "extends": ["plugin:jest/style"] 3}
To enable this configuration with eslint.config.js
, use
jest.configs['flat/style']
:
1const jest = require('eslint-plugin-jest'); 2 3module.exports = [ 4 { 5 files: [ 6 /* glob matching your test files */ 7 ], 8 ...jest.configs['flat/style'], 9 }, 10];
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:
1{ 2 "extends": ["plugin:jest/all"] 3}
To enable this configuration with eslint.config.js
, use
jest.configs['flat/all']
:
1const jest = require('eslint-plugin-jest'); 2 3module.exports = [ 4 { 5 files: [ 6 /* glob matching your test files */ 7 ], 8 ...jest.configs['flat/all'], 9 }, 10];
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.
💼
Configurations
enabled in.
⚠️ Configurations
set to warn in.
✅ Set in the recommended
configuration.
🎨
Set in the style
configuration.
🔧
Automatically fixable by the
--fix
CLI option.
💡
Manually fixable by
editor suggestions.
Name | Description | 💼 | ⚠️ | 🔧 | 💡 |
---|---|---|---|---|---|
consistent-test-it | Enforce test and it usage conventions | 🔧 | |||
expect-expect | Enforce assertion to be made in a test body | ✅ | |||
max-expects | Enforces a maximum number assertion calls in a test body | ||||
max-nested-describe | Enforces a maximum depth to nested describe calls | ||||
no-alias-methods | Disallow alias methods | ✅ | 🎨 | 🔧 | |
no-commented-out-tests | Disallow commented out tests | ✅ | |||
no-conditional-expect | Disallow calling expect conditionally | ✅ | |||
no-conditional-in-test | Disallow conditional logic in tests | ||||
no-confusing-set-timeout | Disallow confusing usages of jest.setTimeout | ||||
no-deprecated-functions | Disallow use of deprecated functions | ✅ | 🔧 | ||
no-disabled-tests | Disallow disabled tests | ✅ | |||
no-done-callback | Disallow using a callback in asynchronous tests and hooks | ✅ | 💡 | ||
no-duplicate-hooks | Disallow duplicate setup and teardown hooks | ||||
no-export | Disallow using exports in files containing tests | ✅ | |||
no-focused-tests | Disallow focused tests | ✅ | 💡 | ||
no-hooks | Disallow setup and teardown hooks | ||||
no-identical-title | Disallow identical titles | ✅ | |||
no-interpolation-in-snapshots | Disallow string interpolation inside snapshots | ✅ | |||
no-jasmine-globals | Disallow Jasmine globals | ✅ | 🔧 | ||
no-large-snapshots | Disallow large snapshots | ||||
no-mocks-import | Disallow manually importing from __mocks__ | ✅ | |||
no-restricted-jest-methods | Disallow specific jest. methods | ||||
no-restricted-matchers | Disallow specific matchers & modifiers | ||||
no-standalone-expect | Disallow using expect outside of it or test blocks | ✅ | |||
no-test-prefixes | Require using .only and .skip over f and x | ✅ | 🔧 | ||
no-test-return-statement | Disallow explicitly returning from tests | ||||
no-untyped-mock-factory | Disallow using jest.mock() factories without an explicit type parameter | 🔧 | |||
padding-around-after-all-blocks | Enforce padding around afterAll blocks | 🔧 | |||
padding-around-after-each-blocks | Enforce padding around afterEach blocks | 🔧 | |||
padding-around-all | Enforce padding around Jest functions | 🔧 | |||
padding-around-before-all-blocks | Enforce padding around beforeAll blocks | 🔧 | |||
padding-around-before-each-blocks | Enforce padding around beforeEach blocks | 🔧 | |||
padding-around-describe-blocks | Enforce padding around describe blocks | 🔧 | |||
padding-around-expect-groups | Enforce padding around expect groups | 🔧 | |||
padding-around-test-blocks | Enforce padding around afterAll blocks | 🔧 | |||
prefer-called-with | Suggest using toBeCalledWith() or toHaveBeenCalledWith() | ||||
prefer-comparison-matcher | Suggest using the built-in comparison matchers | 🔧 | |||
prefer-each | Prefer using .each rather than manual loops | ||||
prefer-equality-matcher | Suggest using the built-in equality matchers | 💡 | |||
prefer-expect-assertions | Suggest using expect.assertions() OR expect.hasAssertions() | 💡 | |||
prefer-expect-resolves | Prefer await expect(...).resolves over expect(await ...) syntax | 🔧 | |||
prefer-hooks-in-order | Prefer having hooks in a consistent order | ||||
prefer-hooks-on-top | Suggest having hooks before any test cases | ||||
prefer-importing-jest-globals | Prefer importing Jest globals | 🔧 | |||
prefer-jest-mocked | Prefer jest.mocked() over fn as jest.Mock | 🔧 | |||
prefer-lowercase-title | Enforce lowercase test names | 🔧 | |||
prefer-mock-promise-shorthand | Prefer mock resolved/rejected shorthands for promises | 🔧 | |||
prefer-snapshot-hint | Prefer including a hint with external snapshots | ||||
prefer-spy-on | Suggest using jest.spyOn() | 🔧 | |||
prefer-strict-equal | Suggest using toStrictEqual() | 💡 | |||
prefer-to-be | Suggest using toBe() for primitive literals | 🎨 | 🔧 | ||
prefer-to-contain | Suggest using toContain() | 🎨 | 🔧 | ||
prefer-to-have-length | Suggest using toHaveLength() | 🎨 | 🔧 | ||
prefer-todo | Suggest using test.todo | 🔧 | |||
require-hook | Require setup and teardown code to be within a hook | ||||
require-to-throw-message | Require a message for toThrow() | ||||
require-top-level-describe | Require test cases and hooks to be inside a describe block | ||||
valid-describe-callback | Enforce valid describe() callback | ✅ | |||
valid-expect | Enforce valid expect() usage | ✅ | 🔧 | ||
valid-expect-in-promise | Require promises that have expectations in their chain to be valid | ✅ | |||
valid-title | Enforce valid titles | ✅ | 🔧 |
Name | Description | 💼 | ⚠️ | 🔧 | 💡 |
---|---|---|---|---|---|
unbound-method | Enforce unbound methods are called with their expected scope |
In order to use the rules powered by TypeScript type-checking, you must be using
@typescript-eslint/parser
& adjust your eslint config as outlined
here.
Note that unlike the type-checking rules in @typescript-eslint/eslint-plugin
,
the rules here will fallback to doing nothing if type information is not
available, meaning it's safe to include them in shared configs that could be
used on JavaScript and TypeScript projects.
Also note that unbound-method
depends on @typescript-eslint/eslint-plugin
,
as it extends the original unbound-method
rule from that plugin.
This is a sister plugin to eslint-plugin-jest
that provides support for the
matchers provided by
jest-extended
.
https://github.com/jest-community/eslint-plugin-jest-extended
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
A set of rules to enforce good practices for Istanbul, one of the code coverage tools used by Jest.
No vulnerabilities found.
Reason
27 commit(s) and 7 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
1 existing vulnerabilities detected
Details
Reason
Found 4/28 approved changesets -- score normalized to 1
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
security policy file not detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn Moreeslint-plugin-jest-dom
ESLint plugin to follow best practices and anticipate common mistakes when writing tests with jest-dom
eslint-plugin-jest-extended
Eslint rules for Jest Extended
@nx/angular
The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: - Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, Playwright and Cypre
@nrwl/angular
The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: - Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, and Cypress. - Gen