node-jest/jest-snapshot-serializer-raw/README.md

2.0 KiB

jest-snapshot-serializer-raw

npm build coverage

jest snapshot serializer for reducing escapes in the snapshot file

(This package is modified from prettier/prettier:tests_config/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