This is a serializer for Enzyme backed by enzyme-to-json, I suggest looking at enzyme-to-json
for the implementation details
npm install --save-dev jest-serializer-enzyme
"jest": {
"snapshotSerializers": ["<rootDir>/node_modules/jest-serializer-enzyme"]
}
More about Jest's snapshotSerializer config here.
import React from 'react';
import { shallow } from 'enzyme';
const Bar = ({ text }) => <p>{text}</p>
const Foo = () => (
<div>
<Bar text="The text" />
</div>
);
it('Renders', () => {
const wrapper = shallow(<Foo />);
expect(wrapper).toMatchSnapshot();
});