mockr

0.1.1 • Public • Published

node-mockr Build Status Coverage Status

Simple mock framework

Install

npm install mockr

Usage

coming...

Example

// pass `before` and `after` hooks, and mockr handles the rest
var mock = require('mockr')(beforeEach, afterEach);
var should = require('should');
 
var mylib = {
  method: function(cb) {
    this.other(cb);
  },
  other: function(cb) {
    console.log('whoops, original');
    cb();
  }
};
 
describe('My awesome library', function() {
  describe('My awesome async method', function() {
    // override mylib.other with a stub (async style)
    // before/after hooks are registered here
    // returns a function to set return/error value per testcase
    var other = mock(mylib, 'other');
    it('should call `other`', function() {
      mylib.method(function(err) {
        mylib.other.called.should.be.true;
      });
    });
    it('should return foo', function() {
      // other now returns foo
      other('foo');
      mylib.method(function(err, foo) {
        foo.should.equal('foo');
      });
    });
    it('should return error sometimes', function() {
      other(new Error());
      mylib.method(function(err) {
        should.exist(err);
      });
    });
  });
});

License

MIT

Author

@madbence

Readme

Keywords

none

Package Sidebar

Install

npm i mockr

Weekly Downloads

0

Version

0.1.1

License

MIT

Last publish

Collaborators

  • lennon