1.0.0 • Published 8 years ago
http-client-x-mock v1.0.0
HTTP client X Mock
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 University Of Helsinki (The National Library Of Finland)
This project's source code is licensed under the terms of GNU General Public License Version 3 or any later version.
1.0.0
8 years ago