0
假設我想加入我自己的特殊存根擴展興農: 我可以只寫:如何使用自定義方法和字段擴展沙盒興農
sinon.specialStub = function() {
return this.stub().returns('SPECIAL');
};
或者,我可以用sinon.extend和寫類似:
sinon.extend(sinon, {
specialStub: function() {
return this.stub().returns('SPECIAL');
}
});
這樣做基本上是一樣的。
一切都會按預期工作,但調用var sandbox = sinon.sandbox.create();
這種方法將會失敗。
這裏是唯一已知的解決方法,我能想到的:
var sandbox = sinon.extend(sinon.sandbox.create(), {
specialStub: function() {
return this.stub().returns('SPECIAL');
}
});
的quesion是 - 沒有任何一個知道如何擴展興農和看到沙盒的擴展方法是什麼?