jest-snapshot-serializer-raw

jest snapshot serializer for reducing escapes in the snapshot file

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
jest-snapshot-serializer-raw
10121.2.02 years ago4 years agoMinified + gzip package size for jest-snapshot-serializer-raw in KB

Readme

jest-snapshot-serializer-raw
npm build coverage
jest snapshot serializer for reducing escapes in the snapshot file
(This package is modified from prettier/prettier:testsconfig/raw-serializer.js@9ec1da1a)
Changelog

Install

# using npm
npm install --save-dev jest-snapshot-serializer-raw

# using yarn
yarn add --dev jest-snapshot-serializer-raw

Usage

Apply to specified snapshots

{
  "snapshotSerializers": ["jest-snapshot-serializer-raw"]
}

// test.js

const { wrap } = require('jest-snapshot-serializer-raw');
const example = `paragraph "one"\n\n'paragraph' \\two\\`;

test('before', () => {
  expect(example).toMatchSnapshot();
});

test('after', () => {
  expect(wrap(example)).toMatchSnapshot();
});

// test.js.snap

exports[`before 1`] = `
"paragraph \\"one\\"

'paragraph' \\\\two\\\\"
`;

exports[`after 1`] = `
paragraph "one"

'paragraph' \\two\\
`;

Apply to all snapshots

{
  "snapshotSerializers": ["jest-snapshot-serializer-raw/always"]
}

// test.js

const example = `paragraph "one"\n\n'paragraph' \\two\\`;

test('after', () => {
  expect(example).toMatchSnapshot();
});

// test.js.snap

exports[`after 1`] = `
paragraph "one"

'paragraph' \\two\\
`;

Development

# lint
yarn run lint

# build
yarn run build

# test
yarn run test

License

MIT © Ika