{"id":18685075,"url":"https://github.com/enzymejs/react-shallow-renderer","last_synced_at":"2025-04-12T04:32:52.479Z","repository":{"id":42424362,"uuid":"172046475","full_name":"enzymejs/react-shallow-renderer","owner":"enzymejs","description":"Shallow rendering for React.","archived":false,"fork":false,"pushed_at":"2023-03-04T05:51:53.000Z","size":963,"stargazers_count":35,"open_issues_count":23,"forks_count":13,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-26T00:11:14.994Z","etag":null,"topics":["javascript","react","testing"],"latest_commit_sha":null,"homepage":"","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/enzymejs.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-22T10:28:26.000Z","updated_at":"2025-02-06T14:42:26.000Z","dependencies_parsed_at":"2024-06-18T13:53:59.031Z","dependency_job_id":null,"html_url":"https://github.com/enzymejs/react-shallow-renderer","commit_stats":{"total_commits":297,"total_committers":57,"mean_commits":"5.2105263157894735","dds":0.7878787878787878,"last_synced_commit":"802c735ee53bf2d965797760698cacbd46088f66"},"previous_names":["nminhnguyen/react-shallow-renderer"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enzymejs%2Freact-shallow-renderer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enzymejs%2Freact-shallow-renderer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enzymejs%2Freact-shallow-renderer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enzymejs%2Freact-shallow-renderer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/enzymejs","download_url":"https://codeload.github.com/enzymejs/react-shallow-renderer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248517375,"owners_count":21117442,"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":["javascript","react","testing"],"created_at":"2024-11-07T10:20:21.199Z","updated_at":"2025-04-12T04:32:50.395Z","avatar_url":"https://github.com/enzymejs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `react-shallow-renderer`\n\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/enzymejs/react-shallow-renderer/blob/master/LICENSE)\n[![npm version](https://img.shields.io/npm/v/react-shallow-renderer)](https://www.npmjs.com/package/react-shallow-renderer)\n[![CircleCI](https://img.shields.io/circleci/build/github/enzymejs/react-shallow-renderer)](https://circleci.com/gh/enzymejs/react-shallow-renderer/tree/master)\n\nWhen writing unit tests for React, shallow rendering can be helpful. Shallow rendering lets you render a component \"one level deep\" and assert facts about what its render method returns, without worrying about the behavior of child components, which are not instantiated or rendered. This does not require a DOM.\n\n## Installation\n\n```sh\n# npm\nnpm install react-shallow-renderer --save-dev\n\n# Yarn\nyarn add react-shallow-renderer --dev\n```\n\n## Usage\n\nFor example, if you have the following component:\n\n```jsx\nfunction MyComponent() {\n  return (\n    \u003cdiv\u003e\n      \u003cspan className=\"heading\"\u003eTitle\u003c/span\u003e\n      \u003cSubcomponent foo=\"bar\" /\u003e\n    \u003c/div\u003e\n  );\n}\n```\n\nThen you can assert:\n\n```jsx\nimport ShallowRenderer from 'react-shallow-renderer';\n// in your test:\nconst renderer = new ShallowRenderer();\nrenderer.render(\u003cMyComponent /\u003e);\nconst result = renderer.getRenderOutput();\nexpect(result.type).toBe('div');\nexpect(result.props.children).toEqual([\n  \u003cspan className=\"heading\"\u003eTitle\u003c/span\u003e,\n  \u003cSubcomponent foo=\"bar\" /\u003e,\n]);\n```\n\nShallow testing currently has some limitations, namely not supporting refs.\n\n\u003e Note:\n\u003e\n\u003e We also recommend checking out Enzyme's [Shallow Rendering API](https://airbnb.io/enzyme/docs/api/shallow.html). It provides a nicer higher-level API over the same functionality.\n\n## Reference\n\n### `shallowRenderer.render()`\n\nYou can think of the shallowRenderer as a \"place\" to render the component you're testing, and from which you can extract the component's output.\n\n`shallowRenderer.render()` is similar to [`ReactDOM.render()`](https://reactjs.org/docs/react-dom.html#render) but it doesn't require DOM and only renders a single level deep. This means you can test components isolated from how their children are implemented.\n\n### `shallowRenderer.getRenderOutput()`\n\nAfter `shallowRenderer.render()` has been called, you can use `shallowRenderer.getRenderOutput()` to get the shallowly rendered output.\n\nYou can then begin to assert facts about the output.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenzymejs%2Freact-shallow-renderer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fenzymejs%2Freact-shallow-renderer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenzymejs%2Freact-shallow-renderer/lists"}