【发布时间】:2021-09-14 20:54:27
【问题描述】:
我有一个像这样的第 3 方模块
class Test {
async doSomething() {}
}
export const testObject = new Test(); <--- I want to mock this part because constructor requires some input which I don't want to provide as it is not required for tests
导入上述模块的另一个模块
import { testObject } from 'module1';
function foo() {
testObject.doSomething()
}
现在我正在尝试编写如下所示的单元测试
describe('test', ()=> {
test('', ()=> {
foo()
})
})
new Test() 依赖于我不想提供的一些外部输入,因此当我运行测试时,由于缺少输入而失败,我不确定如何阻止 new Test() 按原样执行,而是应该运行模拟函数
【问题讨论】:
标签: javascript node.js unit-testing ts-jest