
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
eslint-snapshot-rule-tester
Advanced tools
A snapshot-based replacement for ESLint's RuleTester.
This package combines the power of ESLint's RuleTester
and the simplicity of snapshot testing. Snapshots are stored in a diff-friendly custom format, making it easy to review changes.
npm install --save-dev eslint-snapshot-rule-tester
Requirements
- ESLint v8.4.0 or above
- Node.js v18.x or above
- Mocha v6.0.0 or above OR Jest v28.0.0 or above
Write tests like you usually would with ESLint's RuleTester
, but use SnapshotRuleTester
instead and omit errors
and output
for invalid test cases.
Example:
// file: tests/rules/no-strings.test.js
import { SnapshotRuleTester } from "eslint-snapshot-rule-tester"
import rule from "../path/to/rules/no-strings"
const tester = new SnapshotRuleTester()
tester.run("no-strings", rule, {
valid: [
String.raw`1 + 2 + 3`
],
invalid: [
`const a = ["foo", "bar"]${"\n"}const b = a.join("\\n")`,
],
})
A snapshot file will be created in a __snapshots__
directory next to the test file:
Test: no-strings >> invalid
Code:
1 | const a = ["foo", "bar"]
| ^~~~~ ^~~~~
| [1] [2]
2 | const b = a.join("\n")
| ^~~~ [3]
Output:
1 | const a = [42, 42]
2 | const b = a.join(42)
[1] Strings are not allowed. Use a number instead.
[2] Strings are not allowed. Use a number instead.
[3] Strings are not allowed. Use a number instead.
---
For the full example, see the test file here and snapshot file here.
To update snapshots, run the tests with the --update
or -u
flag:
mocha tests/**/*.js --update
jest -u
FAQs
A snapshot-based replacement for ESLint's RuleTester.
The npm package eslint-snapshot-rule-tester receives a total of 193 weekly downloads. As such, eslint-snapshot-rule-tester popularity was classified as not popular.
We found that eslint-snapshot-rule-tester demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.