由于一些设计问题,我必须在特殊钩子中存根对象的功能。
问题:可以多次调用钩子。然后我需要知道该函数是否已被存根。
问题:如何避免两次短截?
示例:的
// throws "undefined is not a function" if `doSOmething`
obj.doSomething.restore(); hasn't been stubbed yet
sinon.stub(obj, "doSomething", function() { alert('Stub!'); });
//throw an exception if `doSomething` function has been already stubbed
sinon.stub(obj, "doSomething", function() { alert('Stub!'); });
答案 0 :(得分:1)
1.首先在钩子中测试函数
2.测试钩子函数,存根/间谍钩子
不同的水平。