jest-img-snapshot
Jest matcher for image comparisons using [pixelmatch](https://github.com/mapbox/pixelmatch) with all the goodness of Jest snapshots out of the box.
Last updated 2 years ago by donysukardi .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install jest-img-snapshot 
SYNC missed versions from official npm registry.

jest-img-snapshot

Jest matcher for image comparisons using pixelmatch with all the goodness of Jest snapshots out of the box.

This project was heavily inspired by jest-image-snapshot.

Overview

Internally, it uses Jest's snapshot features by keeping track of snapshot changes using checksum of the serialized image, passing and failing the snapshot tests accordingly. This means you get interactive update for failing snapshot tests, removal of obsolete snapshots out of the box.

Note that when update flag is not specified and the image comparison falls within the specified threshold, the library will not perform any update and pass the test using the previously stored checksum.

Usage

  1. Extend Jest's expect with toMatchImageSnapshot exposed by the library
const { toMatchImageSnapshot } = require('jest-image-snapshot');
expect.extend({ toMatchImageSnapshot });
  1. Or use configureToMatchImageSnapshot to specify default configuration (refer to Optional Configuration below for details)
const { configureToMatchImageSnapshot } = require('jest-image-snapshot');
const toMatchImageSnapshot = configureToMatchImageSnapshot({
  customDiffConfig: { threshold: 0.1 },
  noColors: false,
  failureThresholdType: 'percent',
  failureThreshold: 0.01
});
expect.extend({ toMatchImageSnapshot });
  1. Finally, use expect(...).toMatchImageSnapshot() in your tests
it('should match image snapshot', () => {
  // ...
  expect(img).toMatchImageSnapshot();
});

Optional configuration

The following configuration can be passed as object to both configureToMatchImageSnapshot as default and expect(...).toMatchImageSnapshot as override for particular tests,

  • customDiffConfig, options passed to pixelmatch. Default: { threshold: 0.01 }
  • noColors, flag to disable chalk coloring. Default: false
  • failureThresholdType, used in conjuction with failureThreshold, options are pixel (default) or percent
  • failureThreshold, used in conjunction with failureThresholdType, for percent, it ranges from 0-1. Default: 0

The following configuration can be used in conjunction with configuration above for expect(...).toMatchImageSnapshot() only,

Current Tags

  • 1.1.0                                ...           latest (2 years ago)

3 Versions

  • 1.1.0                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 1
This Month 1
Last Day 1
Last Week 0
Last Month 3
Dependencies (6)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |