pretty-format is a robust utility for stringifying any JavaScript value, particularly useful for debugging and generating consistent output for snapshot testing. Maintained as a core package within the Jest testing framework, it is currently on version 30.3.0 and aligns its major releases with Jest itself, which aims for more frequent major updates going forward. Key differentiators include its extensibility through a powerful plugin system, allowing serialization of application-specific data types (often called snapshot serializers in the context of Jest). It can handle circular references, various built-in types, and offers extensive configuration options for output style, indentation, and color highlighting.
npm install pretty-formatVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage of `pretty-format` with a complex object, including circular references, various JavaScript types, and the use of built-in React plugins and a simple custom plugin.
Update existing snapshots (`jest --updateSnapshot`) after upgrading to Jest 30 or `pretty-format` v30 to reflect the new rendering behavior. Review the changes to ensure they are intended.
Run Jest with `--updateSnapshot` to accept the new, corrected formatting for `ArrayBuffer` and `DataView` instances in your snapshots. Verify the updated output is as expected.
It is highly recommended to run `jest --updateSnapshot` after upgrading to Jest 30 to re-record any snapshots affected by these underlying formatting improvements. Always review snapshot diffs carefully.
Keep `test` methods simple, fast, and avoid expensive operations. Perform heavy logic only within the `serialize` or `print` methods once `test` has confirmed the plugin should handle the value.
Review the snapshot differences and, if the changes are expected and correct, update your snapshots by running `jest --updateSnapshot`.
Ensure you are using the correct import syntax for your module system. For ESM, use `import { format } from 'pretty-format';`. For CommonJS, use `const { format } = require('pretty-format');`. Verify your bundler/TypeScript configuration is set up to correctly handle module interop.Debug the `test` method to ensure it correctly identifies the target value. Check the `serialize` method for logic errors. Confirm the plugin is included in the `plugins` array passed to the `format` function. Ensure the `serialize` method uses `printer` for child values and `indenter` for new lines as expected.
No dependency data recorded yet.