0.1.4 • Published 9 years ago

mockagent v0.1.4

Weekly downloads
6
License
MIT
Repository
github
Last release
9 years ago

mockagent

Build Status

A mocking utility for superagent in the browser. If you are using Node.js shmock is recommended.

Usage

var superagent = require('superagent');
var mockagent = require('mockagent');

mockagent.target(superagent);

// Make a simply static mock
mockagent.put('/url/to/fake', 201, {data: 'to return'});

superagent.put('/url/to/fake')
// ...

// For more complex mocks, use a function to create the response.
// This function is bound to the superagent Request instance, making
// it possible to check headers, request body, etc.
mockagent.post('/post/url', function(res) {

  if (this.header['Accept'] === 'application/json') {
    res.xhr = {responseText: '...'};
    res.status = 200;
  } else {
    // ...
  }

  return res;
});

// To tear down the mock
mockagent.releaseTarget();

Mockagent can take a single URL to mock, or an array of URLs. The response can be given as an object, or a string. If it is given as an object, it will be serialized to a JSON string before being returned.

Development

Pull it down

$ git clone https://github.com/kahnjw/mockagent.git
$ cd mockagent

Test it

$ npm test

Make pulls against the github repository.

Happy testing!

0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago