jest-snapshot-generate

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

Usage no npm install needed!

<script type="module">
  import jestSnapshotGenerate from 'https://cdn.skypack.dev/jest-snapshot-generate';
</script>

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 :-)