Skip to content

Latest commit

 

History

History
64 lines (45 loc) · 1.61 KB

File metadata and controls

64 lines (45 loc) · 1.61 KB

vitest/no-large-snapshots

📝 Disallow large snapshots.

⚠️ This rule warns in the 🌐 all config.

Rule Details

This rule aims to prevent large snapshots.

Options

Name Description Type
allowedSnapshots Allowed snapshot names by absolute snapshot file path. Object
inlineMaxSize Maximum number of lines allowed in inline snapshots. Number
maxSize Maximum number of lines allowed in external snapshots. Number

This rule accepts an object with the following properties:

  • maxSize (default: 50): The maximum size of a snapshot.
  • inlineMaxSize (default: 0): The maximum size of a snapshot when it is inline.
  • allowedSnapshots (default: []): The list of allowed snapshots.

For example:

{
  "vitest/no-large-snapshots": [
    "error",
    {
      "maxSize": 50,
      "inlineMaxSize": 0,
      "allowedSnapshots": []
    }
  ]
}

Examples of incorrect code for this rule with the above configuration:

test('large snapshot', () => {
  expect('a'.repeat(100)).toMatchSnapshot()
})

Examples of correct code for this rule with the above configuration:

test('large snapshot', () => {
  expect('a'.repeat(50)).toMatchSnapshot()
})

When Not To Use It

If you don't want to limit the size of your snapshots, you can disable this rule.