Skip to content

Latest commit

 

History

History
39 lines (25 loc) · 1.24 KB

no-snapshots.md

File metadata and controls

39 lines (25 loc) · 1.24 KB

Disallows jest snapshots. (no-snapshots)

Jest’s snapshot feature allows you to assert that a value has not changed from a stored value in a previous test. The matchers toMatchSnapshot, toMatchInlineSnapshot, toThrowErrorMatchingSnapshot and toThrowErrorMatchingInlineSnapshot will generate snapshots when used inside test blocks.

Rule Details

Using snapshots will often result in poorly documented, difficult to debug tests that encourage writing a single test to cover a broad area of functionality when seperate, more specific tests would be preferred. This rule aims to prevent the use of jest snapshots.

The following patterns are considered warnings:

expect(doWork()).toMatchSnapshot();
expect(doWork()).toMatchInlineSnapshot();
expect(doWork()).toThrowErrorMatchingSnapshot();
expect(doWork()).toThrowErrorMatchingInlineSnapshot();

The following patterns are not warnings:

expect(doWork()).toHaveProperty('foo', 'bar');

When Not To Use It

If you do not wish to prevent the use of jest snapshots, you can safely disable this rule.

Further Reading