gpt4 book ai didi

javascript - spyOn 静态方法 - Jasmine ES6

转载 作者:行者123 更新时间:2023-11-30 06:20:15 25 4
gpt4 key购买 nike

我有一个创建新实例的类,该实例包含在同一个类中调用的静态方法。我希望监视该方法以确保它是从 jasmine 测试中的其他类方法调用的。

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
});

最佳答案

解决这个问题的方法如下:

spyOn(A.constructor, 'methodB')

关于javascript - spyOn 静态方法 - Jasmine ES6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53585071/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com