🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

snapshot-assertion

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

snapshot-assertion

Asserts a string matches a snapshot saved in a file. An environment variable can be used to save rather than assert snapshots.

5.0.0
latest
Source
npm
Version published
Weekly downloads
25
-26.47%
Maintainers
1
Weekly downloads
 
Created
Source

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 snapshot-assertion with npm, run:

npm install snapshot-assertion --save-dev

Then, import and use the function assertSnapshot.

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

Requirements

Supported runtime environments:

  • Node.js versions ^14.17.0 || ^16.0.0 || >= 18.0.0.

Projects must configure TypeScript to use types from the ECMAScript modules that have a // @ts-check comment:

Exports

The npm package snapshot-assertion features optimal JavaScript module design. These ECMAScript modules are exported via the package.json field exports:

Keywords

snapshot

FAQs

Package last updated on 18 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts