Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

eslint-snapshot-test

fa93hws343.9kMIT3.2.0TypeScript support: included

Provide snapshot test for eslint rule

eslint, snapshot-test

readme

GithubCI Codecov License: MIT npm version TypescriptStrict

How to use

import { SnapshotCreator } from 'eslint-snapshot-tester';
import { semi } from 'eslint/rules/semi';

const eslintOptions = {
  parserOptions: {
    ecmaVersion: 2017,
    sourceType: 'module',
  },
  parser: '@typescript-eslint/parser',
};
const snapshotCreator = new SnapshotCreator(eslintOptions);

const code = "const a = 1";

const { snapshot } = snapshotCreator
  .mark({ code, ruleName: 'semi', rule: semi })
  .render();

const { snapshot } = snapshotCreator
  .mark({ code, ruleName: 'semi', rule: semi })
  .withOptions(["always"], "warn")
  .render();

const { snapshot } = snapshotCreator
  .mark({ code, ruleName: 'semi', rule: semi })
  .overrideConfig({ settings: { foo: 'foo' } })
  .render();

const { snapshot } = snapshotCreator
  .mark({ code, ruleName: 'semi', rule: semi })
  .withFileName('filename.ts')
  .render();