{"library":"pretty-format","title":"Pretty Format","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install pretty-format"],"cli":null},"imports":["import { format } from 'pretty-format';","import { format as prettyFormat } from 'pretty-format';","import { format, plugins } from 'pretty-format';\n// or specific plugins:\nimport { ReactElement, ReactTestComponent } from 'pretty-format/build/plugins';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { format, plugins } from 'pretty-format';\n\nconst { ReactElement, ReactTestComponent } = plugins;\n\nconst val = {\n  string: 'hello world',\n  number: 123.45,\n  boolean: true,\n  array: [-0, Infinity, NaN, null, undefined],\n  object: { key: 'value', nested: { id: 1 } },\n  circularReference: null,\n  map: new Map([['prop', 'value']]),\n  set: new Set([1, 2, 3]),\n  symbol: Symbol('description'),\n  func: function myFunc() {},\n  date: new Date('2023-01-01T12:00:00.000Z')\n};\n\nval.circularReference = val; // Create a circular reference\n\nconst options = {\n  indent: 2,\n  min: false,\n  callToJSON: true,\n  plugins: [ReactElement, ReactTestComponent]\n};\n\nconsole.log(format(val, options));\n\n// Example with a custom plugin (simple)\nconst customPlugin = {\n  test(value) {\n    return value instanceof Error;\n  },\n  serialize(value, config, indentation, depth, refs, printer) {\n    return `Custom Error: ${value.message}`;\n  },\n};\n\nconst error = new Error('Something went wrong');\nconsole.log(format(error, { plugins: [customPlugin] }));","lang":"typescript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}