Lint your Jest unit tests to find problems. Built with Rust.
- Mock checking -- checks that all imports in the module under test have a corresponding
jest.mock()in the test file - Flagged expect args -- flags suspect words (e.g. "stub") inside
expect()calls, since stub values shouldn't be asserted on
All features are enabled by default. Use .jest_lint.json to customize behavior.
First: Install Rust and Cargo
Then, either install the published crate (easy) or download from this repo.
cargo install jest_lint
jest_lint --help
Check all files in the current directory:
jest_lint
Check a specific directory:
jest_lint -d path/to/files
Check specific files:
jest_lint -f path/to/foobar.test.js
jest_lint path/to/foo.test.js path/to/bar.test.js
Download this repository.
cd jest_lint
cargo run -- --help
PRs welcome!
Create a .jest_lint.json file in your project root. The config file is automatically discovered
by searching up from the checked file's directory.
{
"ignoredModules": [
"zod",
"@mui/**",
"*.module.scss",
"next/**",
"**/types/*"
],
"expectArgs": {
"flagged": ["stub"],
"severity": "warning"
}
}Patterns support exact matches and glob syntax (* for single level, ** for nested paths).
You can also ignore individual imports inline in your test file with a comment:
// jest_lint:ignore ./utilsFlags lines where expect() contains a word from the flagged list. This catches cases where
stub values leak into assertions, e.g. expect(stubName).toBe("hello").
| Field | Default | Description |
|---|---|---|
enabled |
true |
Set to false to disable this check |
flagged |
[] |
Words to flag inside expect() calls |
severity |
"error" |
"error" (exit 1) or "warning" (exit 0) |
See the examples directory for a working demo.
If you're using VS Code, you can add a task to .vscode/tasks.json to run jest_lint on the current file:
{
"label": "jest_lint",
"type": "shell",
"command": "jest_lint -f ${file}"
}Then you can use a keyboard shortcut to check your mocks while you have your .spec.* or .test.* file open.