Last active
December 20, 2015 17:49
-
-
Save haiiro-shimeji/6171418 to your computer and use it in GitHub Desktop.
usage of sinon.js
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
TestCase("usage.sinon", { | |
'test mock for constructor': sinon.test(function() { | |
var obj = { | |
hoge: function(id) { | |
this.id = id | |
} | |
}; | |
this.mock(obj) | |
.expects("hoge") | |
.withArgs(2) | |
//.returns(new obj.hoge(2)); //cause expectation error. | |
.returns(Object.create(obj.hoge.prototype, {id: {value: 2}}));//spy | |
assertEquals(2, new obj.hoge(2).id); | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment