Merge pull request #2452 from gradido/fix-jest-run-all-timeers

fix(backend): run all timers for high values
This commit is contained in:
Moriz Wahl 2022-12-01 16:21:37 +01:00 committed by GitHub
commit e458a7dd8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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:`,
)
})