[英]Sinon.js: avoid stubbing twice
由于某些设计问题,我不得不在特殊的钩子中添加对象的功能。
问题:该钩子可以被多次调用。 然后,我需要知道该函数是否已经存根。
问题:如何避免存根两次?
例:
// 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!'); });
1.首先测试钩子中的功能
2.测试钩子功能,存根/监视钩子
不同层次。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.