我有一个类构造函数,有一个要存根的函数:
class Service {
constructor(){}
async someFunction() {
try {
// does stuff
}
catch (e) {}
}
}
在我要测试的文件中,这是像这样导入的:
const { Service } = require('something')
const newService = new Service('xyz')
我正在努力让它在我的测试中正确导入和存根。
目前正在像这样导入:
t.context.service = {
Service: class Service {
constructor () {
this.someFunction = sinon.stub()
}
}
}
此导入似乎有效,但是我无法通过构造版本获得对它的引用。对这个有帮助吗?
我希望能够做出如下断言:
t.true(t.context.service.Service.someFunction.calledOnce)