![CircleCI](https://circleci.com/gh/igor-dv/jest-specific-snapshot.svg?style=svg)
Jest Specific Snapshot
Jest matcher for multiple snapshot files per test
You can read about the implementation here
Installation
npm i -D jest-specific-snapshot
Example
const path = require('path');
require('jest-specific-snapshot');
test('test', () => {
const pathToSnap = path.resolve(process.cwd(), './example/specific/dir/my.shot');
expect(100).toMatchSpecificSnapshot(pathToSnap);
expect(14).toMatchSpecificSnapshot('./specific/dir/my.shot');
expect(19).toMatchSpecificSnapshot('./specific/another_dir/another.shot');
});
With Custom Serializer
const addSerializer = require('jest-specific-snapshot').addSerializer;
addSerializer();
test('test', () => {
expect().toMatchSpecificSnapshot(
'./specific/custom_serializer/test.shot'
);
});
Extend toMatchSpecificSnapshot
const toMatchSpecificSnapshot = require('jest-specific-snapshot').toMatchSpecificSnapshot;
expect.extend({
toMatchDecoratedSpecificSnapshot(received, snapshotFile) {
const data = doSomeThing(received);
return toMatchSpecificSnapshot.call(this, data, snapshotFile);
},
});
Limitations
- Snapshot files should have an extension other than
.snap
, since it conflicts with jest. - 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. .toMatchSpecificSnapshot
does ignore a custom serializers strategy. In order to support custom serializers, you should use the addSerializer
method explicitly.