我有一个类,它创建一个新实例,其中包含在同一个类中调用的静态方法。我希望监视该方法,以确保它是从茉莉花测试的另一个类方法调用的。
A.js
class A {
methodA() {
let check = A.methodB(); // ping
}
static methodB() {
return 'ping'
}
}
export default new A();A.spec.js
import A from './A.js'
it('...', () => {
spyOn(A, 'methodB'); // Error: <spyOn> : methodB() method does not exist
});发布于 2018-12-17 21:49:50
解决这一问题的办法如下:
spyOn(A.constructor, 'methodB')https://stackoverflow.com/questions/53585071
复制相似问题