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.
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');
If you do not wish to prevent the use of jest snapshots, you can safely disable this rule.