unexpected-snapshot

v0.1.1

unexpected-snapshot

NPM version Build Status Coverage Status

Snap!

Unexpected plugin for capturing and matching inline snapshots.

An assertion that matches against a snapshot looks almost like a regular to equal assertion:

const expect = require('unexpected')
  .clone()
  .use(require('unexpected-snapshot'));

expect(something, 'to equal snapshot', 'the value');

expect(somethingElse, 'to equal snapshot', { foo: 123 });

There's a string-based variant for values that involve non-trivial object trees:

function Person(name) {
  this.name = name;
}

expect(
  new Person('Eigil'),
  'to inspect as snapshot',
  "Person({ name: 'Eigil' })"
);

Specify the UNEXPECTED_SNAPSHOT=yes environment variable to update the snapshots for the tests that fail.

Tip: You can easily make an initial recording by leaving out the 3rd argument:

expect(something, 'to equal snapshot');

Note that this recording/injection feature only works when running your tests in node.js. The matching against the snapshot works in all test runners, including the browser.

RELEASES

See the changelog.

Metadata

  • ISC
  • Whatever
  • Unknown
  • released 8/4/2017

Downloads

Maintainers