brittle-snapshot
v1.0.1
Published
Traditional snapshots for brittle
Readme
brittle-snapshot
Snapshot testing for brittle. One snapshot file per test file, multiple snapshots per file.
Install
npm i brittle-snapshotUsage
const test = require('brittle')
const { matchSnapshot } = require('brittle-snapshot')
test('render heading', (t) => {
const html = render('<h1>hello</h1>')
matchSnapshot(t, html)
matchSnapshot(t, render('<h1>world</h1>'), 'second heading')
})Snapshots are written to a __snapshots__ directory alongside the calling test file, named after it:
test/
render.js
__snapshots__/
render.snapEach .snap file contains all snapshots for that test file:
=== render heading > 1 ===
<h1>hello</h1>
=== render heading > second heading ===
<h1>world</h1>API
matchSnapshot(t, source, [desc])
Compare source against a stored snapshot using character-level diffing.
matchSnapshotCSS(t, source, [desc])
Compare using CSS-aware diffing.
matchSnapshotJSON(t, source, [desc])
Compare using JSON-aware diffing.
All functions take:
t— a brittle test instancesource— string to snapshotdesc— optional label for the snapshot key (defaults to an auto-incrementing counter)
Updating snapshots
Run with --update or -u to overwrite existing snapshots:
bare test/render.js --updateor
npm test -- --updateLicense
Apache-2.0
