https://github.com/one-com/mockrequest
A mock version of the 'request' module for use in tests.
https://github.com/one-com/mockrequest
Last synced: 10 months ago
JSON representation
A mock version of the 'request' module for use in tests.
- Host: GitHub
- URL: https://github.com/one-com/mockrequest
- Owner: One-com
- Created: 2014-08-19T09:06:24.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2014-09-12T15:09:41.000Z (almost 12 years ago)
- Last Synced: 2025-07-21T01:39:22.820Z (11 months ago)
- Language: JavaScript
- Size: 267 KB
- Stars: 0
- Watchers: 16
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
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.
[](http://badge.fury.io/js/mockrequest)
[](https://travis-ci.org/One-com/mockrequest)
[](https://coveralls.io/r/One-com/mockrequest)
[](https://david-dm.org/One-com/mockrequest)
Usage
-----
```javascript
var MockRequest = require('mockrequest'),
request = new MockRequest({
request: {
method: 'GET',
url: '/foo'
},
response: {
headers: {
'Content-Type': 'text/html'
},
body: '
Hello!
'
}
});
request.get('/foo', function (err, response, body) {
// response.statusCode === 200
// response.headers['content-type'] === 'text/html'
// body === '
Hello!
'
});
```
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.