Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

snapsnap

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

snapsnap

Tools for snapshotting, replaying, and mocking HTTP queries with Jest

  • 0.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
164
increased by16.31%
Maintainers
1
Weekly downloads
 
Created
Source

Snapsnap

Capture, cache, and replay HTTP queries in your tests using Nock.

Coverage Status Codecov Codacy Maintainability

  1. On the first run, the tests make real HTTP queries.
  2. The queries and the responses are stored in __http__/.
  3. On subsequent runs, cached responses are loaded from __http__/ and used instead of real queries.
  4. This is super helpful if your tests run in an environment that has no internet access, or you wish to maintain a snapshot of the responses.

Usage

Snapsnap behaves similarly to Jest Snapshots. If an HTTP query has not been snapshotted, a real HTTP query will be made. Otherwise, a cached version of the query will be returned.

To signal that a test should be snapshotted, simply use it.snap() instead of it(). The framework will manage the rest.

it.snap(
  'should query the API',
  async () => {
    const result = await request('https://postman-echo.com/get?foo1=bar1&foo2=bar2');
    const json = await result.json();
    
    expect(json).toMatchSnapshot();
  }
);

Setting Up

Jest

Supports Jest with Circus (=default) test runner.

Configuring Jest

Snapsnap is implemented as a test environment that extends Jest's built-in NodeEnvironment.

// ./jest.config.js
module.exports = {
  testEnvironment: 'snapsnap/jest-env.js'
};

Acknowledgments

Based on Jest Nock Back and Jest Nock.

Keywords

FAQs

Package last updated on 06 Jun 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc