prefer-importing-jest-globals
UnreleasedConfiguration
rslint.config.ts
Rule Details
Prefer explicit imports from @jest/globals instead of relying on Jest's
injected globals. That keeps Jest APIs imported consistently across the codebase
and helps migrations when
injectGlobals
cannot be enabled (for example some ESM setups).
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Options
types
A list of Jest global kinds to enforce explicit imports for. By default all Jest
globals are enforced. Restricting types is useful during incremental
migrations — for example enforcing only the jest helper when adopting ESM.
Examples of incorrect code with { "types": ["jest"] }:
Examples of correct code with { "types": ["jest"] }:
Original Documentation
Differences from ESLint
- For
const x = 1, { expect } = require('@jest/globals'), autofix keeps the existingexpectbinding when merging new names. ESLint only reads the first declarator, so it can drop that binding. Sibling declarators such asx = 1are still removed on both sides.