🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

sinon-har-server

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sinon-har-server

Auto mocks your server from a recorded .har file. Don't let your mocks lie to you!

latest
Source
npmnpm
Version
0.3.0
Version published
Maintainers
1
Created
Source

sinon-har-server

Auto mocks your server from a recorded .har file. Don't let your mocks lie to you!

Build Status Coverage Status Dependency Status devDependency Status js-semistandard-style

This module works in Node.js as well as in the browser with either AMD or with a <script> tag which defines sinonHarServer as a global.

Usage:

var server;

beforeEach(function () {
  return fetch('api-traffic.har').then(function (response) {
    return response.json();
  }).then(function (harFile) {
    server = sinon.fakeServer.create();
    server.autoRespond = true;
    server.autoRespondAfter = 1;
    return sinonHarServer.load(server, harFile);
  });
});

afterEach(function () {
  server.restore();
});

This is especially useful for capturing all test traffic from your back-end test suite, for doing auto mocking in your front-end test suite. See this project for an example: https://github.com/larsthorup/http-auto-mock-demo

Blog post about this technique: http://www.zealake.com/2015/01/05/unit-test-your-service-integration-layer/

The .har file can be conveniently produced by https://github.com/larsthorup/node-request-har-capture

Keywords

sinon

FAQs

Package last updated on 20 Mar 2016

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