https://github.com/mukeshsoni/create-snapshot-test
Automatically generate snapshot tests for your react components with random values for the props
https://github.com/mukeshsoni/create-snapshot-test
generated-code jest react reactjs snapshot testing
Last synced: 12 months ago
JSON representation
Automatically generate snapshot tests for your react components with random values for the props
- Host: GitHub
- URL: https://github.com/mukeshsoni/create-snapshot-test
- Owner: mukeshsoni
- Created: 2018-04-18T12:03:52.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-20T12:03:42.000Z (almost 8 years ago)
- Last Synced: 2025-01-22T00:34:01.394Z (about 1 year ago)
- Topics: generated-code, jest, react, reactjs, snapshot, testing
- Language: JavaScript
- Homepage:
- Size: 120 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### jest-create-snapshot
Automatically generate snapshot tests for your react components with random values for the props.
If you specify the path to a folder or directory, it creates snapshot tests for all the components inside that directory. Even for components inside a sub directory inside that directory.
It works best if you have defined types for your props using either [`prop-types`](https://www.npmjs.com/package/prop-types) or using [`flow`](http://flowtype.org/).
It will not work with styled components for now.
Usage -
```
$ npm i -g create-snapshot-test
; All the usage
$ create-shapshot-test --help
Usage: create-snapshot-test [path] [options]
Generate snapshot tests for your React component.
If a directory is passed, it is recursively traversed.
Options:
-o, --out Write the snapshot test in FILE
--no-pretty Don't pass output through prettier. Default - false
optional If you want to generate values for optional props too
-h, --help output usage information
$ create-snapshot-test path/to/component.js
Generated snapshot test
---------------------------------------------------------
import React from "react";
import renderer from "react-test-renderer";
import FakeComponent from "/Users/mukesh/Documents/projects/create-snapshot-test/__tests__/__mocks__/fake_component.js";
test("Should render FakeComponent correctly", () => {
const tree = renderer
.create(
)
.toJSON();
expect(tree).toMatchSnapshot();
});
OR
$ create-snapshot-test path/to/component.js -o __tests__/path/to/test_file.js
```
### API
```
const createSnapshotTest = require('create-snapshot-test')
const snapshotTest = createSnapshotTest('path/to/your/component.js', true /* if you want values to be generated for optional props too */)
```