Gathering detailed insights and metrics for enzyme-to-json
Gathering detailed insights and metrics for enzyme-to-json
Gathering detailed insights and metrics for enzyme-to-json
Gathering detailed insights and metrics for enzyme-to-json
@types/enzyme-to-json
TypeScript definitions for enzyme-to-json
enzyme-to-json-mock-props
it gives you the ability to mock props generated via enzyme-to-json
enzyme-to-json-default-props
convert enzyme wrapper to a format compatible with Jest snapshot
enzyme-db
A powerful object-relational mapping (ORM) and data manipulation library designed to simplify and streamline interaction with local storage and data in JavaScript applications.
npm install enzyme-to-json
Typescript
Module System
Min. Node Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
942 Stars
216 Commits
64 Forks
10 Watchers
14 Branches
38 Contributors
Updated on Jun 01, 2025
Latest Version
3.6.2
Package Id
enzyme-to-json@3.6.2
Size
12.87 kB
Published on
Apr 08, 2021
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
1
25
Convert Enzyme wrappers to a format compatible with Jest snapshot testing.
1$ npm install --save-dev enzyme-to-json
The serializer is the recommended way to use enzyme-to-json
, the installation and usage of it is very easy and allows you to write clean and simple snapshot tests.
In order to use the serializer, just add this line to your Jest configuration:
1"snapshotSerializers": ["enzyme-to-json/serializer"]
For most projects, that is all you need to start using snapshot tests on Enzyme wrappers. The rest of this readme is only showing advanced usages of this library.
In case you are still confused, here is a minimal example project demonstrating this configuration.
You can add the serializer for only one Jest test file by adding these lines at the beginning of your Jest unit test file:
1import {createSerializer} from 'enzyme-to-json'; 2 3expect.addSnapshotSerializer(createSerializer({mode: 'deep'}));
You can also add the serializer for all tests using the setupFilesAfterEnv
configuration option from Jest.
At the beginning, enzyme-to-json
was just a helper because serializers weren't supported by Jest. Even though it is now recommended to use the serializer to keep your tests simple, you can still use the helper as it gives you access to the option objects.
The helper is just a function you can import from enzyme-to-json
and just pass your Enzyme wrapper as the first parameter and snapshot test the returned value, you'll get the same results as if you used the serializer. Note that you don't have to disable the serializer if you had configured it for the rest of your project. Here is a usage example:
1import React, {Component} from 'react'; 2import {shallow} from 'enzyme'; 3import toJson from 'enzyme-to-json'; 4 5it('renders correctly', () => { 6 const wrapper = shallow( 7 <MyComponent className="my-component"> 8 <strong>Hello World!</strong> 9 </MyComponent>, 10 ); 11 12 expect(toJson(wrapper)).toMatchSnapshot(); 13});
The main purpose of using the helper is to use the option object. The option object is just the second argument of the helper, here is an example:
1toJson(wrapper, { 2 noKey: false, 3 mode: 'deep', 4});
And here are all the possible options:
Key | Value | Description |
---|---|---|
noKey | bool | Since v2.0.0 , the key prop is included in the snapshot, you can turn it off if you don't want your key to be in your snapshot by settting this option to true . Only works for the mount and shallow wrappers. |
mode | 'deep' , 'shallow' | The deep option will return a test object rendered to maximum depth while the shallow option will return a test object rendered to minimum depth. Only works for the mount wrappers. See mode documentation for examples. |
map | function | You can change each nested node of your component output by providing the map option. See map documentation for examples. |
ignoreDefaultProps | bool | You can exclude the default props from snapshots in shallow mode |
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 5/11 approved changesets -- score normalized to 4
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
44 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-14
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More