Skip to content

Instantly share code, notes, and snippets.

@madbence
Created January 7, 2014 14:37
Show Gist options
  • Select an option

  • Save madbence/8300192 to your computer and use it in GitHub Desktop.

Select an option

Save madbence/8300192 to your computer and use it in GitHub Desktop.
var mock = require('my-awesome-mock-module')(beforeEach, afterEach);
describe('foo', function() {
var fn = mock(foo, 'bar', [] /* default return value */, true /* async */);
// foo.bar = function(a, b, c) { c(null, []); }
// override in beforeEach hook, restore original in afterEach
it('should qux', function() {
fn([1]); // foo.bar now returns [1] (node async style)
fn(new Error()); // foo.bar now fails
});
// OR
var fn = mock(foo, 'bar', function(a, b, c) { a.should.be.true; c(); });
var fn = mock(foo, 'bar', function(a, b) {}, true); // assert function signature to match with the original function (fail on API changes)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment