Skip to content

Latest commit

 

History

History
41 lines (26 loc) · 1.03 KB

README.md

File metadata and controls

41 lines (26 loc) · 1.03 KB

jest-file-snapshot

Jest matcher to write snapshots to a separate file instead of the default snapshot file used by Jest. Writing a snapshot to a separate file means you have proper syntax highlighting in the output file, and better readability without those pesky escape characters.

Installation

npm install --save-dev jest-file-snapshot

or

yarn add --dev jest-file-snapshot

Usage

Extend Jest's expect:

import { toMatchFile } from 'jest-file-snapshot';

expect.extend({ toMatchFile });

Then use it in your tests:

it("matches content of file on disk", () => {
  expect(content).toMatchFile(filepath);
});

The matcher takes one argument, which is the path to the file whose content should be matched.

You should also exclude the output files from Jest's wacher so that updating the snapshot doesn't re-run the tests again.

Credits