Skip to content

Jest matcher to write snapshots to a separate file instead of the default snapshot file used by Jest

Notifications You must be signed in to change notification settings

segment-boneyard/jest-file-snapshot

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Jest matcher to write snapshots to a separate file instead of the default snapshot file used by Jest

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%