iptpv / superagent-mocker

Pretty simple mocks for the CRUD and REST API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

superagent-mocker

Build Status

Pretty simple mocks for the CRUD and REST API.

Install

npm i superagent-mocker

Usage

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

About

Pretty simple mocks for the CRUD and REST API


Languages

Language:JavaScript 100.0%