{"id":28840789,"url":"https://github.com/algolia/jest-serializer-html","last_synced_at":"2025-06-30T06:30:43.110Z","repository":{"id":40295494,"uuid":"88285887","full_name":"algolia/jest-serializer-html","owner":"algolia","description":"Jest snapshot serializer that beautifies HTML.","archived":false,"fork":false,"pushed_at":"2023-03-03T07:43:00.000Z","size":227,"stargazers_count":53,"open_issues_count":10,"forks_count":8,"subscribers_count":53,"default_branch":"master","last_synced_at":"2025-05-08T09:52:16.233Z","etag":null,"topics":["beautifier","html","jest","serializer","snapshot","unit-testing","vue","vuejs"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/algolia.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-14T16:53:03.000Z","updated_at":"2025-04-06T10:04:21.000Z","dependencies_parsed_at":"2024-06-18T13:56:05.005Z","dependency_job_id":"47336339-3eb9-413c-b577-0a80855665ee","html_url":"https://github.com/algolia/jest-serializer-html","commit_stats":{"total_commits":33,"total_committers":6,"mean_commits":5.5,"dds":0.1515151515151515,"last_synced_commit":"7490cf5a33f6fea0d5ef698ad19c83159475133a"},"previous_names":["rayrutjes/jest-serializer-html"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algolia%2Fjest-serializer-html","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algolia%2Fjest-serializer-html/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algolia%2Fjest-serializer-html/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algolia%2Fjest-serializer-html/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/algolia","download_url":"https://codeload.github.com/algolia/jest-serializer-html/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algolia%2Fjest-serializer-html/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259280661,"owners_count":22833434,"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":["beautifier","html","jest","serializer","snapshot","unit-testing","vue","vuejs"],"created_at":"2025-06-19T15:41:30.855Z","updated_at":"2025-06-30T06:30:43.068Z","avatar_url":"https://github.com/algolia.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A Jest snapshot serializer that beautifies HTML.\n\n[![NPM version](https://badge.fury.io/js/jest-serializer-html.svg)](https://npmjs.org/package/jest-serializer-html)\n[![Build Status](https://travis-ci.org/rayrutjes/jest-serializer-html.svg?branch=master)](https://travis-ci.org/rayrutjes/jest-serializer-html)\n\nWhen using this Jest serializer, it will turn any string starting with '\u003c' to nicely indented HTML in the snapshot.\n\nThis serializer is based on [diffable-html](https://github.com/rayrutjes/diffable-html) which is an opinionated HTML formatter that will ease readability of diffs in case of failing snapshot tests.\n\n## Install\n\nAdd the package as a dev-dependency:\n\n```bash\n# With npm\nnpm install --save-dev jest-serializer-html\n\n# With yarn\nyarn add --dev jest-serializer-html\n```\n\nUpdate package.json to [let Jest know about the serializer](https://facebook.github.io/jest/docs/configuration.html#snapshotserializers-array-string):\n\n```json\n\"jest\": {\n  \"snapshotSerializers\": [\"jest-serializer-html\"]\n}\n```\n\n## Vanilla JS Example\n\n```js\ntest('should beautify HTML', () =\u003e {\n  expect('\u003cul\u003e\u003cli\u003e\u003ca href=\"#\"\u003eMy HTML\u003c/a\u003e\u003c/li\u003e\u003c/ul\u003e').toMatchSnapshot();\n});\n```\n\nWill output:\n\n```js\nexports[`should beautify HTML 1`] = `\n\u003cul\u003e\n  \u003cli\u003e\n    \u003ca href=\"#\"\u003e\n      My HTML\n    \u003c/a\u003e\n  \u003c/li\u003e\n\u003c/ul\u003e\n`;\n```\n\n## Vue.js component output example\n\n```js\nimport Vue from 'vue';\nconst Hello = {\n  props: {\n    msg: {\n      type: String,\n      default: 'World'\n    }\n  },\n  template: `\n    \u003ch1\u003eHello ${ msg }!\u003c/h1\u003e\n    \u003cul id=\"main-list\" class=\"list\"\u003e\u003cli\u003e\u003ca href=\"#\"\u003eMy HTML\u003c/a\u003e\u003c/li\u003e\u003c/ul\u003e\n  `\n};\n\ntest('should beautify HTML', () =\u003e {\n  const Component = Vue.extend(Hello);\n  const vm = new Component({\n    propsData: {\n      msg: 'You'\n    }\n  });\n\n  vm.$mount();\n\n  expect(vm.$el.outerHTML).toMatchSnapshot();\n});\n```\n\nWill output:\n\n```js\nexports[`should beautify HTML 1`] = `\n\u003ch1\u003e\n  Hello You!\n\u003c/h1\u003e\n\u003cul id=\"main-list\"\n    class=\"list\"\n\u003e\n  \u003cli\u003e\n    \u003ca href=\"#\"\u003e\n      My HTML\n    \u003c/a\u003e\n  \u003c/li\u003e\n\u003c/ul\u003e\n`;\n```\n\nYou can read more about the [HTML formatting here](https://github.com/rayrutjes/diffable-html#readme).\n\n## Special thanks\n\nThis package was inspired by the amazing post here: [Jest for all: Episode 1 — Vue.js](https://hackernoon.com/jest-for-all-episode-1-vue-js-d616bccbe186) by [Cristian Carlesso](https://hackernoon.com/@kentaromiura_the_js_guy).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falgolia%2Fjest-serializer-html","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falgolia%2Fjest-serializer-html","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falgolia%2Fjest-serializer-html/lists"}