ESLint Plugin No Snapshot Testing
raw JSON → 1.0.61 verified Sat Apr 25 auth: no javascript
An ESLint plugin (v1.0.61) that enforces a rule disallowing snapshot testing in Jest. It prevents calls to `toMatchSnapshot` and `toMatchInlineSnapshot`, offering an auto-fix to remove them. This package is a niche utility for teams that ban snapshot testing. It has a simple setup, only one rule, and is dependency-light. No known major alternative exists with identical focus.
Common errors
error ESLint couldn't find the plugin "eslint-plugin-no-snapshot-testing". ↓
cause Plugin not installed or ESLint cannot resolve it.
fix
Run
npm install eslint-plugin-no-snapshot-testing --save-dev and check node_modules. error Rule "no-snapshot-testing/no-snapshot-testing" is not defined. ↓
cause Plugin not listed in 'plugins' array or misspelled.
fix
Add 'no-snapshot-testing' to plugins in .eslintrc.
error Cannot read property 'rule' of undefined ↓
cause Invalid plugin configuration: using 'rules' with wrong format.
fix
Ensure plugins array contains 'no-snapshot-testing' and rules object key is 'no-snapshot-testing/no-snapshot-testing'.
Warnings
gotcha The rule name is repetitive: 'no-snapshot-testing/no-snapshot-testing'. ↓
fix Use exactly as documented; no alternative rule name exists.
gotcha Only disallows Jest snapshot matchers; not other snapshot-like patterns (e.g., manual file snapshots). ↓
fix Extend rule or use additional ESLint configurations if needed.
gotcha Auto-fix removes the entire `expect(...).toMatchSnapshot()` line; may remove other chained matchers if on same line. ↓
fix Ensure snapshot call is on its own line before auto-fix.
gotcha No support for custom matchers that wrap snapshot testing. ↓
fix Plugin is intentionally limited; consider custom ESLint rules for advanced cases.
Install
npm install eslint-plugin-no-snapshot-testing yarn add eslint-plugin-no-snapshot-testing pnpm add eslint-plugin-no-snapshot-testing Imports
- plugin (default) wrong
plugins: ['eslint-plugin-no-snapshot-testing']correctplugins: ['no-snapshot-testing'] - rule (no-snapshot-testing/no-snapshot-testing) wrong
rules: { 'no-snapshot-testing/no-snapshot': 'error' }correctrules: { 'no-snapshot-testing/no-snapshot-testing': 'error' } - rule options wrong
rules: { 'no-snapshot-testing/no-snapshot-testing': ['error', { ... }] }correctrules: { 'no-snapshot-testing/no-snapshot-testing': ['error', { ... }] }
Quickstart
// .eslintrc.js
module.exports = {
plugins: ['no-snapshot-testing'],
rules: {
'no-snapshot-testing/no-snapshot-testing': 'error',
},
};
// test.js
const x = 1;
expect(x).toMatchSnapshot(); // ESLint error + fix removes this line