{"id":13459110,"url":"https://github.com/typicode/react-fake-props","last_synced_at":"2025-04-08T13:07:52.850Z","repository":{"id":42363670,"uuid":"92867289","full_name":"typicode/react-fake-props","owner":"typicode","description":"🔮 Magically generate fake props for your React tests ","archived":false,"fork":false,"pushed_at":"2024-02-14T10:26:22.000Z","size":2557,"stargazers_count":626,"open_issues_count":8,"forks_count":23,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-01T11:08:51.987Z","etag":null,"topics":["enzyme","flow","props","proptypes","react","test"],"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/typicode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"typicode"}},"created_at":"2017-05-30T19:11:46.000Z","updated_at":"2025-02-11T15:49:24.000Z","dependencies_parsed_at":"2023-02-06T11:16:10.496Z","dependency_job_id":"d4946b1d-50d7-4bbe-a3a5-4b9bd86b8ce8","html_url":"https://github.com/typicode/react-fake-props","commit_stats":{"total_commits":87,"total_committers":7,"mean_commits":"12.428571428571429","dds":"0.25287356321839083","last_synced_commit":"71b458b26b7d96303f06f9c40853367b93e66b93"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typicode%2Freact-fake-props","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typicode%2Freact-fake-props/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typicode%2Freact-fake-props/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/typicode%2Freact-fake-props/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/typicode","download_url":"https://codeload.github.com/typicode/react-fake-props/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247847611,"owners_count":21006100,"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":["enzyme","flow","props","proptypes","react","test"],"created_at":"2024-07-31T09:01:04.557Z","updated_at":"2025-04-08T13:07:52.822Z","avatar_url":"https://github.com/typicode.png","language":"JavaScript","funding_links":["https://github.com/sponsors/typicode"],"categories":["JavaScript"],"sub_categories":[],"readme":"# react-fake-props [![Node.js CI](https://github.com/typicode/react-fake-props/actions/workflows/node.js.yml/badge.svg)](https://github.com/typicode/react-fake-props/actions/workflows/node.js.yml) [![npm](https://badge.fury.io/js/react-fake-props.svg)](https://www.npmjs.com/package/react-fake-props)\n\n\u003e Magically generate fake props for your React tests 🔮\n\n`react-fake-props` parses your Component prop types using [react-docgen](https://github.com/reactjs/react-docgen) and generates fake props. Supports [TypeScript](https://www.typescriptlang.org/), [Flow](https://flow.org) and [PropTypes](https://github.com/facebook/prop-types). Works great with [Jest](https://facebook.github.io/jest/) snapshots and [Enzyme](https://github.com/airbnb/enzyme).\n\n## Install\n\n```sh\nnpm install react-fake-props --save-dev\n```\n\n```sh\nyarn add react-fake-props --dev\n```\n\n## Example\n\nAssuming the following Component with TypeScript:\n\n```jsx\ntype Props = {\n  id: number\n  name: string\n}\n\nclass Component extends React.Component\u003cProps\u003e {\n  // ...\n}\n```\n\nOr Flow types:\n\n```jsx\n// @flow\ntype Props = {\n  id: number,\n  name: string\n}\n\nclass Component extends React.Component\u003cProps\u003e {\n  // ...\n}\n```\n\nOr PropTypes:\n\n```jsx\nclass Component extends React.Component {\n  // ...\n}\n\nComponent.propTypes = {\n  id: PropTypes.number.isRequired,\n  name: PropTypes.string.isRequired\n}\n```\n\nWith `react-fake-props`, you can generate valid props based on your Component prop types:\n\n```jsx\nconst props = fakeProps(componentPath)\n/*\n{\n  id: 1,\n  name: 'name'\n}\n*/\n\u003cComponent {...props} /\u003e\n```\n\n## Usage\n\n```js\nimport path from 'path'\nimport fakeProps from 'react-fake-props'\n\nconst componentPath = path.join(__dirname, './Component.jsx')\nconst props = fakeProps(componentPath)\n```\n\nTo include optional props, pass `{ optional: true }`.\n\nPlease note:\n- `custom` validators and `PropTypes.instanceOf` aren't supported, you'll still need to set them manually.\n- `react-fake-props` requires the component path to be passed, instead of the component itself, to be able to support TypeScript, Flow and PropTypes.\n\n### For multiple components in single file\n\nBy passing `{ all: true }`, `fakeProps` will return an array of all components found in `componentPath` with corresponding fake props. Works even for the ones that aren't exported.\n\n```js\n// Pick the component you want to get fake props using displayName\nconst components = fakeProps(componentPath, { all: true })\nconst { props } = components.find({ displayName } =\u003e displayName === 'SomeComponent')\n```\n\n## API\n\n`fakeProps(componentPath[, { optional: false, all: false } ])`\n\n## Tip\n\nWhen checking for a value, use `props.A` rather than `'A'` as `react-fake-props` output may change.\n\n```jsx\nconst wrapper = shallow(\u003cComponent {...props} /\u003e)\n\nwrapper.text().to.contain('A') // bad\nwrapper.text().to.contain(props.A) // good\n```\n\n## See also\n\n* [react-lodash](https://github.com/typicode/react-lodash) - Lodash as React components\n\n## License\n\nMIT - [Typicode :cactus:](https://github.com/typicode)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypicode%2Freact-fake-props","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftypicode%2Freact-fake-props","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypicode%2Freact-fake-props/lists"}