Novel Preposterous Mockery
Have opinions about JavaScript? We want to hear them. Take the 2018 JavaScript Ecosystem Survey »


2.2.0 • Public • Published


Greenkeeper badge Build Status

Tapshot is a helper module for snapshot testing when you are using tools like tap and tape. Tapshot can be used to test any serializable object.



$ npm install --save-dev tapshot


As of V2, tapshot will not automatically add new snapshots or snapshot files. You'll need to pass the 'update' option to save them. See Updating Snapshots for how to do this.


tapshot(tap, object[, options])

  • tap object or function: A tap class that has the equal and pass methods. If you're not setting name in options, this also needs to contain a name, which will be provided if you use it within a named subtest
  • object any: The object that you want to snapshot. This can be any serializable object. If it is a non-standard object, a serializer must be provided in options.
  • options object: The options to run the test with. These are all optional:
    • name string: The name for the snapshot
    • file string: The location of the snapshot file you wish to use
    • serializer string or function: The serializer for the object provided if it is a non-standard object. If passed as a string, it will call that method on the object, if passed as a function, the funtion will be called with the object as the only argument.
    • update boolean: If set to true, the snapshot for this test will be updated


This will return a tapshot instance that is configured to use the options passed in as defaults. This instance can be used the same as above.

  • options object: The options to configure the tapshot instance with. These are optional:
    • file string: The location of the snapshot file you wish to use
    • update boolean: If set to true, the snapshots will be updated

Updating Snapshots

If you change the structure of the object being snapshotted, you will need to update your snapshots. There are 3 ways to do this:

update Option

Set the update option when calling tapshot. Like so:

tapshot(t, `console.log('this is a string of text')`, {update: true});

This will only update the snapshot for that specific test.

update Configuration Option

Set the update option when calling tapshot.configure(). Like so:

tapshot.configure({update: true});

This will update the snapshots for any tests that use that instance.


const tap = require(`tap`);
const tapshot = require(`tapshot`);
tap.test(`Generated code is as expected`, (t) => {
    tapshot(t, `console.log('this is a string of text')`);
const tap = require(`tap`);
const tapshot = require(`tapshot`);
tap.test(`Generated code is as expected`, (t) => {
    tapshot(t, `console.log('this is a string of text')`, {name: 'generated-code'});
const tap = require(`tap`);
const tapshot = require(`tapshot`).configure({update: true});
tap.test(`Generated code is as expected`, (t) => {
    tapshot(t, `console.log('this is a string of text')`);


MIT © Luke Bonaccorsi




npm i tapshot

Downloadsweekly downloads









last publish


  • avatar
Report a vulnerability