From 41495c2c654e9b8ff260a341b748441831defca1 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Thu, 1 Dec 2022 15:53:09 +0100 Subject: [PATCH] fix(backend): run all timers for high values --- backend/src/graphql/resolver/util/creations.test.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/backend/src/graphql/resolver/util/creations.test.ts b/backend/src/graphql/resolver/util/creations.test.ts index 8d747e989..6be317e16 100644 --- a/backend/src/graphql/resolver/util/creations.test.ts +++ b/backend/src/graphql/resolver/util/creations.test.ts @@ -170,8 +170,11 @@ describe('util/creation', () => { const targetDate = new Date(now.getFullYear(), now.getMonth() + 1, 0, 23, 0, 0) beforeAll(() => { + const halfMsToRun = (targetDate.getTime() - now.getTime()) / 2 jest.useFakeTimers() - setTimeout(jest.fn(), targetDate.getTime() - now.getTime()) + setTimeout(jest.fn(), halfMsToRun) + jest.runAllTimers() + setTimeout(jest.fn(), halfMsToRun) jest.runAllTimers() }) @@ -225,8 +228,10 @@ describe('util/creation', () => { }) it('has the clock set correctly', () => { + const targetMonth = nextMonthTargetDate.getMonth() + 1 + const targetMonthString = (targetMonth < 10 ? '0' : '') + String(targetMonth) expect(new Date().toISOString()).toContain( - `${nextMonthTargetDate.getFullYear()}-${nextMonthTargetDate.getMonth() + 1}-01T01:`, + `${nextMonthTargetDate.getFullYear()}-${targetMonthString}-01T01:`, ) })