Skip to content

neotan/jest-snapshot-delete-properties

Repository files navigation

Delete properties from snapshot

Use this serializer to remove any unwanted properties from snapshot, keeping it sparkling clean ✨

Install

Add the package as a dev dependency

# With npm
npm install --save-dev jest-snapshot-delete-properties

# With yarn
yarn add --dev jest-snapshot-delete-properties

Register serializer with Jest in your setupTests.js:

import snapshotDeleteProperties from "jest-snapshot-delete-properties";

expect.addSnapshotSerializer(snapshotDeleteProperties(["want-to-delete-attr1", "want-to-delete-attr2"]));

Vanilla JS Example

test('should remove data attributes', () => {
  expect(<Component want-to-delete-attr1="bye" id="keep-me">Children</Component>).toMatchSnapshot();
});

Will output:

exports[`should remove data attributes`] = `
<div
  id="keep-me"
>
  Children
</div>
`;

About

Use this serializer to remove any unwanted properties from snapshot, keeping it sparkling clean ✨

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published