Jest Specific Snapshot

Jest matcher for multiple snapshot files per test

You can read about the implementation here


npm i -D jest-specific-snapshot


const path = require('path');
// extend jest to have 'toMatchSpecificSnapshot' matcher

test('test', () => {
  // provides snapshot file with absolute file
  const pathToSnap = path.resolve(process.cwd(), './example/specific/dir/my.shot');

  //same snapshot but with relative file

  // another snapshot file in the same test

With Custom Serializer

// extend jest to have 'toMatchSpecificSnapshot' matcher
const addSerializer = require('jest-specific-snapshot').addSerializer;

addSerializer(/* Add custom serializer here */);

test('test', () => {
  expect(/* thing that matches the custom serializer */).toMatchSpecificSnapshot(

Extend toMatchSpecificSnapshot

const toMatchSpecificSnapshot = require('jest-specific-snapshot').toMatchSpecificSnapshot;

  toMatchDecoratedSpecificSnapshot(received, snapshotFile) {
    // You can modify received data or create dynamic snapshot path
    const data = doSomeThing(received);
    return, data, snapshotFile);


  1. Snapshot files should have an extension other than .snap, since it conflicts with jest.
  2. In order to handle the --updateSnapshot (-u) parameter provided from CLI, there is an abuse of the SnapshotState._updateSnapshot private field. TBD - try to use the globalConfig to get this state.
  3. .toMatchSpecificSnapshot does ignore a custom serializers strategy. In order to support custom serializers, you should use the addSerializer method explicitly.

Jest Specific Snapshot

Jest matcher for multiple snapshot files per test

Jest Specific Snapshot Info

⭐ Stars 41
🔗 Source Code
🕒 Last Update a year ago
🕒 Created 5 years ago
🐞 Open Issues 3
➗ Star-Issue Ratio 14
😎 Author igor-dv