Package Exports
- superagent-mocker
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (superagent-mocker) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
superagent-mocker
Pretty simple mocks for the CRUD and REST API.
Install
npm i superagent-mockerUsage
Setup
var request = require('superagent');
var mock = require('superagent-mocker')(request);Get
mock.get('/topics/:id', function(req) {
var id = req.params.id;
return { id: req.params.id, content: 'Hello World!' };
});
request
.get('/topics/1')
.end(function(err, data) {
console.log(data); // { id: 1, content: 'Hello World' }
})
;Post
mock.post('/topics/:id', function(req) {
return {
id: req.params.id,
content: req.body.content
};
});
request
.post('/topics/5', { content: 'Hello world' })
.end(function(err, data) {
console.log(data); // { id: 5, content: 'Hello world' }
})
;mock.put() and mock.del() methods works as well.
Note
Sadly, but request.send() doesn't work :( Sorry
License
MIT © Shuvalov Anton