Search code examples
reactjsjestjscreate-react-appreact-scripts

What's react-scripts Jest default serializer for snapshot testing?


The only information I've found is in this link:

The default Jest coverage configuration can be overriden by adding any of the following supported keys to a Jest config in your package.json.

Supported overrides:

  • collectCoverageFrom
  • coverageReporters
  • coverageThreshold
  • snapshotSerializers

Inside my node_modules/react-scripts/utils/createJestConfig.js, the jest config object doesn't have a snapshotSerializers default property. I didn't find information about this anywhere else in the CRA's user guide, nor in the closed issues.

What's the default serializer?


Solution

  • You can check the jest-snapshot module to confirm the same. Jest uses this module for everything related to snapshot from serializing to snapshot assertions.

    There is a module: pretty-format in jest packages from which Jest imports default serializers for React Elements, HTML elements, mock functions, JS built-in types, etc.

    Code blob where jest-snapshot adds default serializers: https://github.com/facebook/jest/blob/master/packages/jest-snapshot/src/plugins.js

    pretty-format docs: https://github.com/facebook/jest/tree/master/packages/pretty-format