【发布时间】:2021-11-11 12:44:59
【问题描述】:
在javascript中拥有
class GrandParent {
myfunc() {
console.log('Parent myfunc');
}
}
class Parent extends GrandParent {
myfunc() {
// do something else here
for (let i = 0; i < 3; i++) {
super.myfunc()
}
}
}
class Child extends Parent {
mymeth() {
// do something here
this.myfunc();
}
}
let spy = sinon.spy(Child.<?>, "myfunc")
let child = new Child();
child.myfunc();
console.log(spy.callCounts); --> 3 expected
我只能访问 Child 类(通过仅导出此类的要求,不得更改)并且我想从 GrandParent 类中监视 myfunc() 方法以获取 spy.callCounts === 3 最后。
有没有可能,怎么做?
提前致谢
【问题讨论】:
标签: javascript sinon