1.0.1 • Published 7 years ago

@natlibfi/http-client-x-mock v1.0.1

Weekly downloads
1
License
LGPL-3.0+
Repository
github
Last release
7 years ago

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.