{"id":21193671,"url":"https://github.com/danielmschmidt/jest-react-rendering","last_synced_at":"2025-06-20T07:33:11.375Z","repository":{"id":38886198,"uuid":"180984144","full_name":"DanielMSchmidt/jest-react-rendering","owner":"DanielMSchmidt","description":null,"archived":false,"fork":false,"pushed_at":"2025-04-30T17:09:20.000Z","size":755,"stargazers_count":0,"open_issues_count":21,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-30T18:25:03.136Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DanielMSchmidt.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"zenodo":null}},"created_at":"2019-04-12T10:15:48.000Z","updated_at":"2019-04-13T11:46:17.000Z","dependencies_parsed_at":"2023-10-12T05:38:13.315Z","dependency_job_id":"c2056d00-d20b-4c1b-84b7-27eae5779d19","html_url":"https://github.com/DanielMSchmidt/jest-react-rendering","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/DanielMSchmidt/jest-react-rendering","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanielMSchmidt%2Fjest-react-rendering","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanielMSchmidt%2Fjest-react-rendering/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanielMSchmidt%2Fjest-react-rendering/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanielMSchmidt%2Fjest-react-rendering/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DanielMSchmidt","download_url":"https://codeload.github.com/DanielMSchmidt/jest-react-rendering/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanielMSchmidt%2Fjest-react-rendering/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260901121,"owners_count":23079710,"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-11-20T19:15:13.746Z","updated_at":"2025-06-20T07:33:06.362Z","avatar_url":"https://github.com/DanielMSchmidt.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Jest Environment React Rendering [![Build Status](https://travis-ci.com/DanielMSchmidt/jest-react-rendering.svg?branch=master)](https://travis-ci.com/DanielMSchmidt/jest-react-rendering)\n\nThis is a jest environment extending [`jest-environment-jsdom`](https://github.com/facebook/jest/tree/master/packages/jest-environment-jsdom) with helpers inspired by [maicki/why-did-you-update](https://github.com/maicki/why-did-you-update).\n\nThe goal is to make rendering improvements testable.\n\n## Setup\n\n`npm install --save-dev jest-react-rendering`\n\nAs this environment mutates React you don't want to use it everywhere, we suggest you enable it per test case via a comment.\nWe bring a mutated copy of React which you need to use, therefore please don't do `import React from \"react\"` in your tests.\n\n```js\n/**\n * @jest-environment react-rendering\n */\nconst React = global.React;\n```\n\n## Usage\n\n```js\n/**\n * @jest-environment react-rendering\n */\nconst React = global.React;\nimport TestRenderer from \"react-test-renderer\";\n\nclass Counter extends React.Component {\n  constructor() {\n    super();\n    this.state = {\n      count: 0\n    };\n\n    this.increment = this.increment.bind(this);\n  }\n\n  increment() {\n    this.setState(state =\u003e ({\n      count: state.count + 1\n    }));\n  }\n\n  render() {\n    return (\n      \u003cdiv\u003e\n        \u003ch1\u003e{this.state.count}\u003c/h1\u003e\n        \u003cbutton onClick={this.increment}\u003eInc\u003c/button\u003e\n      \u003c/div\u003e\n    );\n  }\n}\n\ndescribe(\"Counter\", () =\u003e {\n  it(\"does not update on initial render\", () =\u003e {\n    TestRenderer.create(\u003cCounter /\u003e);\n\n    expect(MyComponent).toBeUpdatedTimes(0);\n  });\n\n  it(\"updates when the button is clicked\", () =\u003e {\n    const renderer = TestRenderer.create(\u003cCounter /\u003e);\n    const instance = renderer.root;\n    const button = instance.find(el =\u003e el.type == \"button\");\n    button.props.onClick();\n\n    expect(Counter).toBeUpdatedTimes(1);\n  });\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielmschmidt%2Fjest-react-rendering","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielmschmidt%2Fjest-react-rendering","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielmschmidt%2Fjest-react-rendering/lists"}