1.1.2 • Published 10 years ago

mockrequest v1.1.2

Weekly downloads
3
License
ISC
Repository
github
Last release
10 years ago

node-mockrequest

A mock version of the request module for use in tests. It "plays back" a sequence of request/response pairs that you specify up front.

NPM version Build Status Coverage Status Dependency Status

Usage

var MockRequest = require('mockrequest'),
    request = new MockRequest({
        request: {
            method: 'GET',
            url: '/foo'
        },
        response: {
            headers: {
                'Content-Type': 'text/html'
            },
            body: '<p>Hello!</p>'
        }
    });

request.get('/foo', function (err, response, body) {
    // response.statusCode === 200
    // response.headers['content-type'] === 'text/html'
    // body === '<p>Hello!</p>'
});

Requests can be specified either as a string (interpreted as a url with an optional method before it) or an object, which can have method, url, headers, and body properties. The request body can be provided as either a string or a Buffer instance.

Responses can be specified as either a number (status code), a string or Buffer (the body), or an object with headers, statusCode, and body properties. The response body can be specified as either a string, a Buffer instance. Support for readable streams is being worked on.

For your convenience, request and response headers can be specified in any casing. They will be normalized to the lower-case form.

1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago