jest-snapshot-generate

Automatically generates snapshot files for your project React / React-native projects

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
jest-snapshot-generate
911.0.07 years ago7 years agoMinified + gzip package size for jest-snapshot-generate in KB

Readme

A jest snapshot generator script
This script runs through all of the files in a given path and creates a /__tests__ folder containing jest snapshots if it thinks the files is a react component. It works with both React and React-native

Installation

npm install jest-snapshot-generator -D
The output of the generated test files looks like this
import React from 'react';
import renderer from 'react-test-renderer';
import NameOfYourComponent from '../NameOfYourComponent';
test('Should render NameOfYourComponent correctly', () => {
    const tree = renderer.create(
        <NameOfYourComponent /> 
    ).toJSON();
    expect(tree).toMatchSnapshot();
});

API

First parameter is the path you want the script to search for react components.

The script also targets sub-folders by running recursively through them all.

The second parameter is the file extension. By default its .js.

Example

Tests

npm test

Contributing

Feel free to improve :-)