{"id":18278072,"url":"https://github.com/tanem/jest-prettyhtml-matchers","last_synced_at":"2025-10-07T22:45:42.167Z","repository":{"id":37270293,"uuid":"179859169","full_name":"tanem/jest-prettyhtml-matchers","owner":"tanem","description":":black_joker: Custom Jest snapshot matchers that use prettyhtml to format strings.","archived":false,"fork":false,"pushed_at":"2024-04-13T16:52:42.000Z","size":3187,"stargazers_count":1,"open_issues_count":3,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-13T18:01:55.013Z","etag":null,"topics":["custom","javascript","jest","matchers","prettyhtml","snapshot","testing","typescript"],"latest_commit_sha":null,"homepage":"https://npm.im/jest-prettyhtml-matchers","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tanem.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null}},"created_at":"2019-04-06T16:36:36.000Z","updated_at":"2024-04-18T20:50:25.062Z","dependencies_parsed_at":"2024-02-27T01:28:59.275Z","dependency_job_id":"624078ef-7038-499a-8e4f-046f97fd7f6f","html_url":"https://github.com/tanem/jest-prettyhtml-matchers","commit_stats":{"total_commits":991,"total_committers":4,"mean_commits":247.75,"dds":0.4248234106962664,"last_synced_commit":"50402efae9adf6bdd331a83912d1728dc347b7a6"},"previous_names":[],"tags_count":196,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanem%2Fjest-prettyhtml-matchers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanem%2Fjest-prettyhtml-matchers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanem%2Fjest-prettyhtml-matchers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanem%2Fjest-prettyhtml-matchers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tanem","download_url":"https://codeload.github.com/tanem/jest-prettyhtml-matchers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247980830,"owners_count":21027803,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["custom","javascript","jest","matchers","prettyhtml","snapshot","testing","typescript"],"created_at":"2024-11-05T12:22:52.244Z","updated_at":"2025-10-07T22:45:37.109Z","avatar_url":"https://github.com/tanem.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jest-prettyhtml-matchers\n\n[![npm version](https://img.shields.io/npm/v/jest-prettyhtml-matchers.svg?style=flat-square)](https://www.npmjs.com/package/jest-prettyhtml-matchers)\n[![build status](https://img.shields.io/github/actions/workflow/status/tanem/jest-prettyhtml-matchers/ci.yml?style=flat-square)](https://github.com/tanem/jest-prettyhtml-matchers/actions?query=workflow%3ACI)\n[![coverage status](https://img.shields.io/codecov/c/github/tanem/jest-prettyhtml-matchers.svg?style=flat-square)](https://codecov.io/gh/tanem/jest-prettyhtml-matchers)\n[![npm downloads](https://img.shields.io/npm/dm/jest-prettyhtml-matchers.svg?style=flat-square)](https://www.npmjs.com/package/jest-prettyhtml-matchers)\n\n\u003e Custom [Jest](https://jestjs.io/en/) snapshot matchers that use [prettyhtml](https://github.com/Prettyhtml/prettyhtml) to format strings.\n\n[Basic Usage](#basic-usage) | [API](#api) | [Installation](#installation) | [License](#license)\n\n## Basic Usage\n\nFirst, add the custom matchers to Jest. A convenient way to do this is via a setup file included in [`setupFilesAfterEnv`](https://jestjs.io/docs/en/configuration.html#setupfilesafterenv-array):\n\n```ts\n// setupJest.js\nimport { createPrettyHtmlMatchers } from 'jest-prettyhtml-matchers'\nexpect.extend(createPrettyHtmlMatchers())\n```\n\n\u003e Note for TypeScript users: To ensure the global jest declaration is augmented correctly, this file should be [included via your TypeScript configuration](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html). There's an example of this setup in [tanem/react-svg](https://github.com/tanem/react-svg).\n\nNow you can use the custom matchers in your tests:\n\n```ts\nexpect(string).toMatchPrettyHtmlSnapshot()\nexpect(string).toMatchInlinePrettyHtmlSnapshot()\n```\n\n## API\n\n### `createPrettyHtmlMatchers(options?: PrettyHtmlOptions)`\n\nGenerates the custom matchers so that they can be [added](https://jestjs.io/docs/en/expect#expectextendmatchers) to Jest.\n\n#### Arguments\n\n- `options` - _Optional_ An object containing prettyhtml options. If `options` is not provided, [prettyhtml's default options](https://github.com/Prettyhtml/prettyhtml#options) will be used when formatting strings. If `options` is provided, it will be merged with prettyhtml's default options, and the merged options will be used when formatting strings. In both cases, the options will apply to all usages of the custom matchers, but can be overridden in the matcher calls themselves.\n\n#### Examples\n\n```js\ncreatePrettyHtmlMatchers()\ncreatePrettyHtmlMatchers({ singleQuote: false }))\n```\n\n\u003chr /\u003e\n\n### `toMatchPrettyHtmlSnapshot(options?: PrettyHtmlOptions, hint?: string)`\n\nEnsures that a value formatted with prettyhtml matches the most recent snapshot.\n\n#### Arguments\n\n- `options` - _Optional_ An object containing prettyhtml options. These options take precedence over options defined globally in `createPrettyHtmlMatchers`.\n- `hint` - _Optional_ A string that is appended to the test name.\n\n#### Examples\n\n```js\nexpect(string).toMatchPrettyHtmlSnapshot()\nexpect(string).toMatchPrettyHtmlSnapshot('testName')\nexpect(string).toMatchPrettyHtmlSnapshot({ singleQuote: false })\nexpect(string).toMatchPrettyHtmlSnapshot({ singleQuote: false }, 'testName')\n```\n\n\u003chr /\u003e\n\n### `toMatchInlinePrettyHtmlSnapshot(options?: PrettyHtmlOptions, inlineSnapshot?: string)`\n\nEnsures that a value formatted with prettyhtml matches the most recent snapshot.\n\n#### Arguments\n\n- `options` - _Optional_ An object containing prettyhtml options. These options take precedence over options defined globally in `createPrettyHtmlMatchers`.\n- `inlineSnapshot` - _Optional_ Jest adds this string to the matcher in the test file (instead of an external `.snap` file) the first time that the test runs.\n\n#### Examples\n\n```js\nexpect(string).toMatchInlinePrettyHtmlSnapshot()\nexpect(string).toMatchInlinePrettyHtmlSnapshot({ singleQuote: false })\n```\n\n\u003chr /\u003e\n\n## Installation\n\n```\n$ npm install -D jest-prettyhtml-matchers\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftanem%2Fjest-prettyhtml-matchers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftanem%2Fjest-prettyhtml-matchers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftanem%2Fjest-prettyhtml-matchers/lists"}