{"id":13493897,"url":"https://github.com/adriantoine/enzyme-to-json","last_synced_at":"2025-05-14T11:10:36.634Z","repository":{"id":39737716,"uuid":"67807611","full_name":"adriantoine/enzyme-to-json","owner":"adriantoine","description":"Snapshot test your Enzyme wrappers","archived":false,"fork":false,"pushed_at":"2023-01-06T01:44:59.000Z","size":1261,"stargazers_count":943,"open_issues_count":22,"forks_count":64,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-05-04T21:02:04.566Z","etag":null,"topics":["enzyme","enzyme-helper","enzyme-wrappers","jest","jest-serializer","react","serializer","snapshot-testing","unit-testing"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adriantoine.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-09T14:52:25.000Z","updated_at":"2025-05-04T15:18:43.000Z","dependencies_parsed_at":"2023-02-05T02:01:09.747Z","dependency_job_id":null,"html_url":"https://github.com/adriantoine/enzyme-to-json","commit_stats":null,"previous_names":[],"tags_count":55,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adriantoine%2Fenzyme-to-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adriantoine%2Fenzyme-to-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adriantoine%2Fenzyme-to-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adriantoine%2Fenzyme-to-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adriantoine","download_url":"https://codeload.github.com/adriantoine/enzyme-to-json/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254129490,"owners_count":22019628,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["enzyme","enzyme-helper","enzyme-wrappers","jest","jest-serializer","react","serializer","snapshot-testing","unit-testing"],"created_at":"2024-07-31T19:01:19.848Z","updated_at":"2025-05-14T11:10:31.616Z","avatar_url":"https://github.com/adriantoine.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Packages"],"sub_categories":["Snapshot"],"readme":"# enzyme-to-json\n\n[![Build Status](https://img.shields.io/travis/adriantoine/enzyme-to-json.svg?branch=master\u0026style=flat-square)](https://travis-ci.org/adriantoine/enzyme-to-json)\n[![codecov](https://img.shields.io/codecov/c/github/adriantoine/enzyme-to-json.svg?style=flat-square)](https://codecov.io/gh/adriantoine/enzyme-to-json)\n[![npm Version](https://img.shields.io/npm/v/enzyme-to-json.svg?style=flat-square)](https://www.npmjs.com/package/enzyme-to-json)\n[![License](https://img.shields.io/npm/l/enzyme-to-json.svg?style=flat-square)](https://www.npmjs.com/package/enzyme-to-json)\n[![Downloads](https://img.shields.io/npm/dm/enzyme-to-json.svg?style=flat-square)](https://npm-stat.com/charts.html?package=enzyme-to-json)\n\nConvert [Enzyme](http://airbnb.io/enzyme/) wrappers to a format compatible with [Jest snapshot testing](https://facebook.github.io/jest/docs/tutorial-react.html#snapshot-testing).\n\n# Install\n\n```console\n$ npm install --save-dev enzyme-to-json\n```\n\n# Usage\n\nThe 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.\n\nIn order to use the serializer, just add this line to your [Jest configuration](https://facebook.github.io/jest/docs/en/configuration.html):\n\n```js\n\"snapshotSerializers\": [\"enzyme-to-json/serializer\"]\n```\n\n[Example](https://github.com/adriantoine/enzyme-to-json-v3-testing/blob/master/package.json#L25-L29)\n\nFor 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.\n\nIn case you are still confused, [here is a minimal example project](https://github.com/adriantoine/enzyme-to-json-v3-testing) demonstrating this configuration.\n\n# Advanced usage\n\n## Serializer in unit tests\n\nYou can add the serializer for only one Jest test file by adding these lines at the beginning of your Jest unit test file:\n\n```js\nimport {createSerializer} from 'enzyme-to-json';\n\nexpect.addSnapshotSerializer(createSerializer({mode: 'deep'}));\n```\n\nYou can also add the serializer for all tests using the [`setupFilesAfterEnv`](https://jestjs.io/docs/en/configuration.html#setupfilesafterenv-array) configuration option from Jest.\n\n## Helper\n\nAt 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.\n\nThe 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:\n\n```js\nimport React, {Component} from 'react';\nimport {shallow} from 'enzyme';\nimport toJson from 'enzyme-to-json';\n\nit('renders correctly', () =\u003e {\n  const wrapper = shallow(\n    \u003cMyComponent className=\"my-component\"\u003e\n      \u003cstrong\u003eHello World!\u003c/strong\u003e\n    \u003c/MyComponent\u003e,\n  );\n\n  expect(toJson(wrapper)).toMatchSnapshot();\n});\n```\n\nThe 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:\n\n```js\ntoJson(wrapper, {\n  noKey: false,\n  mode: 'deep',\n});\n```\n\nAnd here are all the possible options:\n\n| Key                  | Value                 | Description                                                                                                                                                                                                                               |\n| -------------------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `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.                   |\n| `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. |\n| `map`                | `function`            | You can change each nested node of your component output by providing the map option. See `map` documentation for examples.                                                                                                               |\n| `ignoreDefaultProps` | `bool`                | You can exclude the default props from snapshots in shallow mode                                                                                                                                                                          |\n\n# Docs\n\n- [Helper functions](/docs/helper-functions.md)\n- [Modes](/docs/modes.md)\n- [Map](/docs/map.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadriantoine%2Fenzyme-to-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadriantoine%2Fenzyme-to-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadriantoine%2Fenzyme-to-json/lists"}