0.1.1 • Published 10 years ago

mockr v0.1.1

Weekly downloads
3
License
-
Repository
github
Last release
10 years ago

node-mockr

Simple mock framework

Install

npm install mockr

Usage

coming...

Example

// pass `before` and `after` hooks, and mockr handles the rest
var mock = require('./')(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

0.1.1

10 years ago

0.1.0

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago