【发布时间】:2019-04-09 02:09:42
【问题描述】:
我找不到存根 es5 类对象方法的正确方法。如果我可以在调用 new A() 时返回假对象/类,它也会起作用。
我尝试过的
sinon.stub(A, 'hello').callsFake(() => console.log("stubbed"))
sinon.stub(A.prototype, 'hello').callsFake(() => console.log("stubbed"))
sinon.stub(A, 'constructor').callsFake(() => {hello: ()=>console.log("stubbed")})
function A () {
this.hello = function() {
console.log("hello");
}
}
new A().hello();
预期输出:存根
当前输出:你好
【问题讨论】:
-
这个帖子可能对你有帮助 github.com/sinonjs/sinon/issues/1892
-
Object.setPrototypeOf(A, sinon.stub().callsFake(function() { console.log('I am Super Stub!'); } ));似乎不起作用
标签: javascript typescript sinon