1. jest-snapshot-serializer-raw
jest snapshot serializer for reducing escapes in the snapshot file
jest-snapshot-serializer-raw
Package: jest-snapshot-serializer-raw
Created by: ikatyang
Last modified: Sat, 15 Jul 2023 07:31:51 GMT
Version: 2.0.0
License: MIT
Downloads: 71,035
Repository: https://github.com/ikatyang/jest-snapshot-serializer-raw

Install

npm install jest-snapshot-serializer-raw
yarn add jest-snapshot-serializer-raw

jest-snapshot-serializer-raw

npm
build

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

 npm install jest-snapshot-serializer-raw

Note: This package is now pure ESM, you may want to install jest-snapshot-serializer-raw@1 if you'd like to use it in CJS environment

Usage

Apply to specified snapshots

In setup file or test file:

 import serializerRaw from 'jest-snapshot-serializer-raw'
expect.addSnapshotSerializer(serializerRaw)

In test file:

 import { wrap } from 'jest-snapshot-serializer-raw'
const example = `paragraph "one"\n\n'paragraph' \\two\\`

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

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

In snapshot file:

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

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

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

'paragraph' \\two\\
`

Apply to all snapshots

In setup file or test file:

 import serializerRaw from 'jest-snapshot-serializer-raw/always'
expect.addSnapshotSerializer(serializerRaw)

In test file:

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

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

In snapshot file:

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

'paragraph' \\two\\
`

Development

 # lint
pnpm run lint

# build
pnpm run build

# test
pnpm run test

License

MIT © Ika

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin