Created
January 7, 2014 14:37
-
-
Save madbence/8300192 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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