Skip to content

Instantly share code, notes, and snippets.

@haiiro-shimeji
Last active December 20, 2015 17:49
Show Gist options
  • Save haiiro-shimeji/6171418 to your computer and use it in GitHub Desktop.
Save haiiro-shimeji/6171418 to your computer and use it in GitHub Desktop.
usage of sinon.js
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