Unleash awesomeness. Private packages, team management tools, and powerful integrations. Get started with npm Orgs »

sinon-har-server

0.3.0 • Public • Published

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

install

npm i sinon-har-server

Downloadsweekly downloads

340

version

0.3.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability