Last active
August 29, 2015 14:02
-
-
Save igorparrabastias/9b0fdc0d367fb44a4d40 to your computer and use it in GitHub Desktop.
node.js: Stubbing with gently and assert modules
This file contains 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 gently = new (require('gently')) | |
, assert = require('assert') | |
function Dog() { | |
} | |
Dog.prototype.seeCat = function() { | |
console.log('seeing cat...'); | |
this.bark('whuf, whuf'); | |
this.run(); | |
} | |
Dog.prototype.bark = function(bark) { | |
console.log('real: ' + bark) | |
} | |
var dog = new Dog(); | |
gently.expect(dog, 'bark', function(bark) { | |
assert.equal(bark, 'whuf, whuf'); | |
console.log('fake: ' + bark) | |
}); | |
gently.expect(dog, 'run'); | |
dog.seeCat(); // executing dog action | |
--- | |
Both "expect" calls fake the real Dog methods. Even Dog.prototype.run() that does not exist. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment