{"id":15354912,"url":"https://github.com/capaj/react-snappy","last_synced_at":"2025-10-12T19:33:40.862Z","repository":{"id":57345019,"uuid":"71468703","full_name":"capaj/react-snappy","owner":"capaj","description":"utility for testing react components against html snapshots","archived":false,"fork":false,"pushed_at":"2016-12-07T22:26:20.000Z","size":58,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-10T19:54:18.262Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/capaj.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":"2016-10-20T13:58:28.000Z","updated_at":"2019-08-03T01:33:45.000Z","dependencies_parsed_at":"2022-09-16T18:11:05.087Z","dependency_job_id":null,"html_url":"https://github.com/capaj/react-snappy","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/capaj%2Freact-snappy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/capaj%2Freact-snappy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/capaj%2Freact-snappy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/capaj%2Freact-snappy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/capaj","download_url":"https://codeload.github.com/capaj/react-snappy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247226191,"owners_count":20904467,"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":[],"created_at":"2024-10-01T12:21:39.099Z","updated_at":"2025-10-12T19:33:35.818Z","avatar_url":"https://github.com/capaj.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-snappy\n\nutility for testing react components against html snapshots\n\n## install\n```bash\nnpm i react-snappy -D\n```\n\n### check\nCompares render output to the snapshot, if not the same prints out a coloured diff and throws an error.\n```javascript\nimport snappy from 'react-snappy';\n\nsnappy.check(\u003cYourComponent/\u003e);\n```\n\n### save\nSaves the html snapshot in the folder `./snapshots` relative to running process current working driectory. You can override this using `setFolder`. Use when you want to add a new component check. Then rewrite to `check`.\nAlternatively you can set envromental variable `SNAPPY_SAVE_ALL` to force every check into a save globally. Use with caution.\n```javascript\nsnappy.save(\u003cYourComponent/\u003e);\n```\n\n### setFolder\njust sets the folder, where snappy will save/look for snapshots. Default value is `snapshots` and it is always relative to the process's current working directory. This is convenient in ava, where each test file has it's own process.\n```javascript\nsnappy.setFolder('./mySpecialSnapshotFolder')\n```\n\n### jsdom\nreinitialize jsdom, html can be any valid html\n```javascript\nsnappy.jsdom(html)\n```\n\n### setColors\nset colors for diffs\n```javascript\nconst chalk = require('chalk')\n\nsnappy.setColors({\n  added: chalk.red,\n  removed: chalk.green\n})  // this is the default\n```\n\n## jsdom and babel\nEnzyme's `mount` is used for rendering under the hood, so you need to have `document` and `window` on global scope-react snappy creates this for you like this:\n```javascript\nconst doc = jsdom.jsdom('\u003chtml\u003e\u003chead\u003e\u003c/head\u003e\u003cbody\u003e\u003c/body\u003e\u003c/html\u003e')\nconst win = doc.defaultView\nglobal.document = doc\nglobal.window = win\n```\nIf you ever need something else in your jsdom, feel free to use the method `jsdom` or just manually rewrite values on `global`.\n\nIf you use ava, best practice is in your `package.json`:\n```json\n\"ava\": {\n  \"require\": [\n    \"babel-register\"\n  ],\n  \"babel\": \"inherit\"\n}\n```\nso that you have the same babel settings as in your app(`.babelrc`).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcapaj%2Freact-snappy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcapaj%2Freact-snappy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcapaj%2Freact-snappy/lists"}