npm.io
0.4.0 • Published 6 years ago

check-snapshot

Licence
MIT
Version
0.4.0
Deps
0
Size
3 kB
Vulns
0
Weekly
0
Stars
1

check-snapshot Build Status Coverage Status

Simple wrapper around jest expect and react-test-renderer to eliminate snapshot testing boilerplate.

Install

yarn add -D check-snapshot

Usage

import snapshot from 'check-snapshot';
import MyComponent from '../MyComponent';

test('MyComponent', () => snapshot(<MyComponent />));
Passing options to renderer.create

If you need to mock a ref you can pass an object as second argument to snapshot function. This object will be passed to renderer.create when serializing your component.

const createNodeMock = () => ({ focus: () => null });
const options = { createNodeMock }

test('MyComponent', () => snapshot(<MyComponent />, options))

// The same as:
test('MyComponent', () => {
    const tree = renderer.create(<MyComponent />, options).toJSON();
    expect(tree).toMatchSnapshot();
});

Keywords