[英]Stubbing a get method using Sinon
我正在嘗試使用屬性存根對象的get方法,
工作良好:
sinon.stub(input.model, 'get');
input.model.get.returns(10);
但考慮一下我們是否需要在對象中存根某些特定屬性,
例如:
input.model.get('yourValue')
↪這怎么可以被打斷? 任何的想法?
stub.withArgs()應該做你想要的。 見http://sinonjs.org/docs/#stubs 。
sinon.stub(input.model, 'get').withArgs('yourValue').returns(10);
Sinon后來改變了這種語法:
class Foo {
get bar() {
return 'yolo';
}
}
const myObj = new Foo();
sinon.stub(myObj, 'bar').get(() => 'swaggins');
myObj.bar; // 'swaggins'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.