You can call expect.addSnapshotSerializer
to add a module that formats application-specific data structures.
For an individual test file, an added module precedes any modules from snapshotSerializers
configuration, which precede the default snapshot serializers for built-in JavaScript types and for React elements. The last module added is the first module tested.
import serializer from 'my-serializer-module';
expect.addSnapshotSerializer(serializer);
// affects expect(value).toMatchSnapshot() assertions in the test file
If you add a snapshot serializer in individual test files instead of to adding it to snapshotSerializers
configuration:
You make the dependency explicit instead of implicit.
You avoid limits to configuration that might cause you to eject from create-react-app.
See configuring Jest for more information.