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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.3.0
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.3.0
    1
  • 0.2.0
    0
  • 0.1.0
    0

Package Sidebar

Install

npm i sinon-har-server

Weekly Downloads

1

Version

0.3.0

License

MIT

Last publish

Collaborators

  • larsthorup