Socket
Socket
Sign inDemoInstall

snapshot-diff-serializer

Package Overview
Dependencies
2
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    snapshot-diff-serializer

A serializer that lets you generate snapshot diffs between two values


Version published
Maintainers
1
Created

Readme

Source

Snapshot Diff Serializer

This is a simple diffing utility for Jest that is inspired by snapshot-diff. The key difference here is that snapshot-diff-serializer only comes as a serializer and is agnostic of other serializers, meaning you get nice diffs with Enzyme, or other serializers applied (something that snapshot-diff doesn't do).

Installation

# npm
npm install --dev snapshot-diff-serializer
# yarn
yarn add -D snapshot-diff-serializer

Configuration

Add the serializer to your snapshotSerializers array in your Jest config (example using package.json)

{
  "jest": {
    "snapshotSerializers": [
      "jest-glamor-react",
      "enzyme-to-json/serializer",
      "<rootDir>/snapshot-diff-serializer"
    ],
  },
}

Usage

Here is an example of using this serializer:

const Component = ({ foo, bar }) => (
  <div>
    {foo != null && foo}
    {bar != null && bar}
  </div>
)
import { shallow } from 'enzyme'
// Test
describe('Component', () => {
  test('variants', () => {
    expect({
      diffA: shallow(<Component foo={3} />),
      diffB: shallow(<Component bar={5} />),
      }).toMatchSnapshot()
  })
})

The produced snapshot would look like this:

exports[`Component variants 1`] = `
- Diff A
+ Diff B

  <div>
-   3
+   5
  </div>
`;

FAQs

Last updated on 02 May 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc