README
snapshot-assertion
Asserts a string matches a snapshot saved in a file. An environment variable can be used to save rather than assert snapshots.
Installation
To install with npm, run:
npm install snapshot-assertion --save-dev
Examples
A snapshot assertion in a test-director
test:
import fetch from "node-fetch";
import assertSnapshot from "snapshot-assertion";
import TestDirector from "test-director";
const tests = new TestDirector();
tests.add("Get a todo.", async () => {
const response = await fetch("https://jsonplaceholder.typicode.com/todos/1");
await assertSnapshot(await response.json(), "snapshots/todo.json");
});
tests.run();
Using the SAVE_SNAPSHOTS
environment variable to save snapshots when running a package script:
SAVE_SNAPSHOTS=1 npm run test
Exports
These ECMAScript modules are published to npm and exported via the package.json
exports
field: