@natlibfi/http-client-x-mock

1.0.1 • Public • Published

HTTP client X mock NPM Version Build Status Test Coverage

A mock for HTTP client X. You can use the module to mock HTTP calls made by HTTP client X, XMLHttpRequest or Node.js's http/https modules.

Usage

The module exports an object which has the following properties:

  • create: This function creates a mock for a HTTP call. It either takes an object for an argument or multiple arguments: url (string), method (string), status (number), headers (object), body (string).
  • restore: Restores original behaviour by removing all mocks set up with create.

Default options for create (url is mandatory):

{
  status: 200,
  method: 'GET',
  headers: {},
  body: ''
}

Node.js

var http_mock = require('http-client-x-mock/lib/nodejs/main');

http_mock.create({
  url: 'http://foo.bar',
  method: 'GET',
  status: 200,
  headers: {
    'X-Foo': 'bar'
  },
  'foobar'	
});

http_mock.restore();

AMD

define(['http-client-x-mock/lib/browser/main'], function(http_mock) {

  http_mock.create({
    url: 'http://foo.bar',
    method: 'GET',
    status: 200,
    headers: {
      'X-Foo': 'bar'
    },
    'foobar'	
  });

  http_mock.restore();

});

Development

Clone the sources and install the package using npm:

npm install

Run the following NPM script to lint, test and check coverage of the code:

npm run check

License and copyright

Copyright (c) 2016-2017 University Of Helsinki (The National Library Of Finland)

This project's source code is licensed under the terms of GNU Lesser General Public License Version 3 or any later version.

Package Sidebar

Install

npm i @natlibfi/http-client-x-mock

Weekly Downloads

1

Version

1.0.1

License

LGPL-3.0+

Last publish

Collaborators