https://github.com/cdlewis/snapshotter
Snapshot testing for Tape/Enzyme projects
https://github.com/cdlewis/snapshotter
enzyme javascript react react-native snapshot-testing tape
Last synced: 5 months ago
JSON representation
Snapshot testing for Tape/Enzyme projects
- Host: GitHub
- URL: https://github.com/cdlewis/snapshotter
- Owner: cdlewis
- Created: 2017-02-19T06:58:22.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T06:19:14.000Z (over 3 years ago)
- Last Synced: 2024-05-13T10:04:31.277Z (about 2 years ago)
- Topics: enzyme, javascript, react, react-native, snapshot-testing, tape
- Language: JavaScript
- Homepage:
- Size: 1.07 MB
- Stars: 28
- Watchers: 2
- Forks: 7
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://travis-ci.org/cdlewis/snapshotter)
# Snapshotter
Snapshot testing is a compelling feature but sometimes it isn't possible to port
large projects to tools like Jest. Snapshotter is designed to be a drop-in replacement
for Jest's `toMatchSnapshot` function. For backwards compatibility purposes, it
includes built-in support for serialising Enzyme components.

# Getting Started
## Install
Add the package:
```sh
npm install --save-dev snapshotter
```
Create a snapshots folder (e.g. `mkdir test/snapshots`) and add it to `package.json`. If you do not specify a folder, Snapshotter will default to `test/snapshots`.
```json
"snapshotter": {
"snapshotPath": "./test/snapshots"
}
```
## Usage
```jsx
import compareToSnapshot from 'snapshotter'
import React from 'react'
import { shallow } from 'enzyme'
import test from 'tape'
const TestClass = () => (
Hello World
)
test('TestClass renders', (assert) => {
const shallowWrapper = shallow()
compareToSnapshot(assert, shallowWrapper, 'TestClass')
assert.end()
})
```
## Update snapshots
To update snapshots, set the `UPDATE_SNAPSHOTS` to a non-falsy value.
```sh
UPDATE_SNAPSHOTS=1 npm run test
```