From c16ad6a7a195bbfc3f21665e31e63274b6b87b6f Mon Sep 17 00:00:00 2001 From: Pierre Cavin Date: Sun, 29 Oct 2023 11:00:57 +0100 Subject: [PATCH] test: re-add test case from #740 --- tests/cron.test.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/cron.test.ts b/tests/cron.test.ts index 2a2054f9..5f14edbc 100644 --- a/tests/cron.test.ts +++ b/tests/cron.test.ts @@ -1080,6 +1080,29 @@ describe('cron', () => { job.stop(); expect(callback).toHaveBeenCalledTimes(1); }); + + it('should create recurring job, setTime with actual date, start and run once (#739)', () => { + const callback = jest.fn(); + const clock = sinon.useFakeTimers(); + + const job = new CronJob('0 0 20 * * *', callback); + + const startDate = new Date(Date.now() + 5000); + job.setTime(new CronTime(startDate)); + + job.start(); + + clock.tick(5000); + + expect(callback).toHaveBeenCalledTimes(1); + + clock.tick(60000); + + clock.restore(); + + expect(callback).toHaveBeenCalledTimes(1); + expect(job.running).toBe(false); + }); }); describe('nextDate(s)', () => {