# jest-specific-snapshot

> [![CircleCI](https://circleci.com/gh/igor-dv/jest-specific-snapshot.svg?style=svg)](https://circleci.com/gh/igor-dv/jest-specific-snapshot)

Latest version **8.0.0** (published 2023-03-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install jest-specific-snapshot
pnpm add jest-specific-snapshot
yarn add jest-specific-snapshot
bun add jest-specific-snapshot
```

## Health

**Score 33/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 8.0.0 |
| Published | 2023-03-05 |
| First published | 2017-08-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/jest-specific-snapshot) |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 9.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 59 |
| Maintainers | igor-dv |

## Links

- npm: https://www.npmjs.com/package/jest-specific-snapshot
- Repository: https://github.com/igor-dv/jest-specific-snapshot
- Homepage: https://github.com/igor-dv/jest-specific-snapshot#readme
- Issues: https://github.com/igor-dv/jest-specific-snapshot/issues
- npm.io page: https://npm.io/package/jest-specific-snapshot

## Dependencies (1)

- [jest-snapshot](https://npm.io/package/jest-snapshot.md) ^29.0.0

## Recent versions

- 8.0.0 (latest) — 2023-03-05
- 7.0.0 — 2022-11-23
- 6.0.0 — 2022-11-16
- 5.0.0 — 2021-05-30
- 4.0.0 — 2020-08-12
- 3.0.0 — 2020-02-25
- 2.0.0 — 2019-02-25
- 1.1.0 — 2019-02-10
- 1.0.0 — 2018-06-11
- 0.5.0 — 2018-03-05
- 0.4.0 — 2018-02-28
- 0.3.0 — 2017-12-06
- 0.2.0 — 2017-08-02
- 0.1.0 — 2017-08-01

## README

[![CircleCI](https://circleci.com/gh/igor-dv/jest-specific-snapshot.svg?style=svg)](https://circleci.com/gh/igor-dv/jest-specific-snapshot)

---

# Jest Specific Snapshot

Jest matcher for multiple snapshot files per test

<b>You can read about the implementation [here](https://medium.com/@davydkin.igor/adding-multi-snapshot-testing-to-jest-b61f23cf17ca)</b>

# Installation

```sh
npm i -D jest-specific-snapshot
```

# Example

```js
const path = require('path');
// extend jest to have 'toMatchSpecificSnapshot' matcher
require('jest-specific-snapshot');

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

  //same snapshot but with relative file
  expect(14).toMatchSpecificSnapshot('./specific/dir/my.shot');

  // another snapshot file in the same test
  expect(19).toMatchSpecificSnapshot('./specific/another_dir/another.shot');
});
```

## With Custom Serializer

```js
// 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(
    './specific/custom_serializer/test.shot'
  );
});
```

## Extend `toMatchSpecificSnapshot`

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

expect.extend({
  toMatchDecoratedSpecificSnapshot(received, snapshotFile) {
    // You can modify received data or create dynamic snapshot path
    const data = doSomeThing(received);
    return toMatchSpecificSnapshot.call(this, data, snapshotFile);
  },
});
```

# Limitations

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.

---
_Source: https://npm.io/package/jest-specific-snapshot · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
