HTTP Test
Simply library for powerful and easy testing REST API
Install:
$ npm install httptest --save-dev
Example:
var httptest = ; ; ;
API:
Chaining
Every method will return a httptest
object, so methods can be chained.
httptest(uri)
Create request or group of request object and specify the base uri
.
.post(uri)
Set POST
method of request.
.get(uri)
Set GET
method of request.
.head(uri)
Set HEAD
method of request.
.put(uri)
Set PUT
method of request.
.patch(uri)
Set PATCH
method of request.
.del(uri)
Set DELETE
method of request.
.setParam(param[, value])
Set GET
params of request.
// As object; // As key-value // Resulthttp://localhost:3000/api/1.0/cars?sort=asc
.setBody(body)
Set POST
, PUT
, PATCH
request body
// As object
.setHeader(header[, value])
Set headers of request.
// As object // As key-value
.expectStatus(status)
Check status code of response.
.expectJSON()
Checks the type of the response data. Method also parse JSON and return JavaScript object as res
on .end(callback)
.
.end(callback)
Perform request with given options. Invoke callback(err, res).
Workflow
Possible to create a common options for a group of requests. Also support override of params, headers, body, expect.
var httptest = ; // Common optionsvar http = ; // Test 1http ; // Test 2http ; // Test 3http // Override base options ;
Package manager page
Direct link to the package
License
Released under the MIT license. Copyright (c) 2013-2014 Andrey Chizh.