【发布时间】:2015-07-22 22:35:28
【问题描述】:
所以基本上我有一个函数,只有当参数等于某个值时,我才想对它的行为进行存根。 示例
var sinon = require('sinon');
var foo = {
bar: function(arg1){
return true;
}
};
var barStub = sinon.stub(foo, "bar");
barStub.withArgs("test").returns("Hi");
// Expectations
console.log(foo.bar("test")); //works great as it logs "Hi"
// my expectation is to call the original function in all cases except
// when the arg is "test"
console.log(foo.bar("woo")); //doesnt work as it logs undefined
【问题讨论】:
-
你在哪里定义sinon?
标签: javascript node.js mocking sinon