【发布时间】:2020-12-03 03:36:52
【问题描述】:
我有一个运行调度程序的简单类。
类似这样的:
export class ExportScheduler {
constructor(cron: string, private product: Product) {
cron.schedule(cron, () => this.export());
}
async export(): Promise<any> {
const access = new Accessor(this.product);
return access.calc();
}
}
我想使用 Jest 编写一个测试,它基本上测试调度程序。
beforeEach(() => {
clock = sinon.useFakeTimers();
cut = new ExportScheduler(
'* * * * *',
product
);
});
it('should schedule exports', async () => {
expect(await cut.export).not.toHaveBeenCalled();
clock.tick(70000);
expect(await cut.export).toHaveBeenCalledTimes(1);
}
但它告诉我以下内容:
匹配器错误:接收到的值必须是模拟或间谍函数
我应该如何测试这个调度器。
【问题讨论】:
标签: javascript typescript express testing jestjs