{"id":26412975,"url":"https://github.com/mmmurray/jest-component-snapshot","last_synced_at":"2025-08-16T07:07:11.802Z","repository":{"id":34672268,"uuid":"174007723","full_name":"mmmurray/jest-component-snapshot","owner":"mmmurray","description":"Component snapshot testing made easy.","archived":false,"fork":false,"pushed_at":"2023-01-03T17:23:24.000Z","size":1734,"stargazers_count":7,"open_issues_count":22,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-08-09T08:56:19.954Z","etag":null,"topics":["a11y","a11y-testing","jest","jest-snapshots","puppeteer","react","snapshot","snapshot-testing","typescript"],"latest_commit_sha":null,"homepage":"","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/mmmurray.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-05T19:28:19.000Z","updated_at":"2022-07-27T07:45:42.000Z","dependencies_parsed_at":"2023-01-15T08:31:05.878Z","dependency_job_id":null,"html_url":"https://github.com/mmmurray/jest-component-snapshot","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/mmmurray/jest-component-snapshot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmmurray%2Fjest-component-snapshot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmmurray%2Fjest-component-snapshot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmmurray%2Fjest-component-snapshot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmmurray%2Fjest-component-snapshot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mmmurray","download_url":"https://codeload.github.com/mmmurray/jest-component-snapshot/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmmurray%2Fjest-component-snapshot/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269733510,"owners_count":24466537,"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","status":"online","status_checked_at":"2025-08-10T02:00:08.965Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["a11y","a11y-testing","jest","jest-snapshots","puppeteer","react","snapshot","snapshot-testing","typescript"],"created_at":"2025-03-17T22:53:37.519Z","updated_at":"2025-08-16T07:07:11.350Z","avatar_url":"https://github.com/mmmurray.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jest-component-snapshot 📸\n\n[![Travis](https://travis-ci.com/mmmurray/jest-component-snapshot.svg?branch=master)](https://travis-ci.com/mmmurray/jest-component-snapshot)\n[![npm](https://img.shields.io/npm/v/jest-component-snapshot.svg)](https://www.npmjs.com/package/jest-component-snapshot)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\nComponent snapshot testing made easy.\n\n## Install ⚙️\n\n```bash\nyarn add -D jest-component-snapshot puppeteer\n```\n\n## Usage 🤖\n\nThe recommended way to use this library is by adding the following to your Jest config:\n\n```json\n{\n  \"globalSetup\": \"jest-component-snapshot/setup\",\n  \"globalTeardown\": \"jest-component-snapshot/teardown\",\n  \"setupFilesAfterEnv\": [\"jest-component-snapshot/extend-expect\"]\n}\n```\n\nThis config is optional - the `globalSetup` and `globalTeardown` functions ensure that the same instance of Puppeteer is shared between tests to improve performance. If you do not set these options then a new instance of Puppeteer will be launched for each test.\n\nIf you cannot configure `setupFilesAfterEnv` (such as in [create-react-app](https://github.com/facebook/create-react-app)), you can manually extend Jest in your test files using:\n\n```js\nimport { extendExpect } from 'jest-component-snapshot'\n\nextendExpect()\n```\n\n### Image snapshot tests\n\nCreates an image snapshot from a component using [jest-image-snapshot](https://www.npmjs.com/package/jest-image-snapshot). All of the same options are supported.\n\n```js\ntest('image snapshot from HTML string', () =\u003e {\n  expect('\u003ch1\u003eHello world\u003c/h1\u003e').toMatchImageSnapshot()\n})\n\ntest('image snapshot from DOM element', () =\u003e {\n  const headingElement = document.createElement('h1')\n  headingElement.innerHtml = 'Hello world'\n\n  expect(headingElement).toMatchImageSnapshot()\n})\n\ntest('image snapshot from React element', () =\u003e {\n  expect(\u003ch1\u003eHello world\u003c/h1\u003e).toMatchImageSnapshot()\n})\n```\n\n### A11y snapshot tests\n\nUses Puppeteer to create an [accessibility tree snapshot](https://pptr.dev/#?product=Puppeteer\u0026show=api-class-accessibility). The snapshot is converted to YAML for readability and empty properties and generic containers are removed.\n\n```js\ntest('a11y snapshot from HTML string', () =\u003e {\n  expect('\u003ch1\u003eHello world\u003c/h1\u003e').toMatchA11ySnapshot()\n})\n\ntest('a11y snapshot from DOM element', () =\u003e {\n  const headingElement = document.createElement('h1')\n  headingElement.innerHtml = 'Hello world'\n\n  expect(headingElement).toMatchA11ySnapshot()\n})\n\ntest('a11y snapshot from React element', () =\u003e {\n  expect(\u003ch1\u003eHello world\u003c/h1\u003e).toMatchA11ySnapshot()\n})\n```\n\n### DOM snapshot tests\n\nSnapshots formatted HTML for the given component.\n\n```js\ntest('DOM snapshot from HTML string', () =\u003e {\n  expect('\u003ch1\u003eHello world\u003c/h1\u003e').toMatchDomSnapshot()\n})\n\ntest('DOM snapshot from DOM element', () =\u003e {\n  const headingElement = document.createElement('h1')\n  headingElement.innerHtml = 'Hello world'\n\n  expect(headingElement).toMatchDomSnapshot()\n})\n\ntest('DOM snapshot from React element', () =\u003e {\n  expect(\u003ch1\u003eHello world\u003c/h1\u003e).toMatchDomSnapshot()\n})\n```\n\n## Alternatives 🙌\n\n- [jest-puppeteer](https://github.com/smooth-code/jest-puppeteer)\n- [jest-image-snapshot](https://www.npmjs.com/package/jest-image-snapshot)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmmurray%2Fjest-component-snapshot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmmmurray%2Fjest-component-snapshot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmmurray%2Fjest-component-snapshot/lists"}