I have a simply class which runs a scheduler.
Something like this:
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();
}
}
And I would like to write a test using Jest, which basically tests the scheduler.
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);
}
But it tells me following:
Matcher error: received value must be a mock or spy function
How should I test this scheduler.
Aucun commentaire:
Enregistrer un commentaire