Skip to content

Commit

Permalink
Fix Date.now() mocking in allocateTask test
Browse files Browse the repository at this point in the history
  • Loading branch information
gihoekveld committed Apr 14, 2024
1 parent e5f53e6 commit a30381e
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/helpers/schedule/utils/allocateTask.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import { beforeAll, describe, expect, it, jest } from '@jest/globals'
import { advanceTo } from 'jest-date-mock'
import { afterAll, beforeAll, describe, expect, it, jest } from '@jest/globals'
import { allocateTask } from './allocateTask'
import { Schedule } from '@/entities/Schedule'
import { UnallocatedTask } from '@/entities/UnallocatedTask'
import { DeadlineExceededException } from '@/errors/DeadlineExceededException'

const dateNowDescriptor = Object.getOwnPropertyDescriptor(Date, 'now')
if (dateNowDescriptor && dateNowDescriptor.configurable) {
jest.doMock('jest-date-mock')
}

describe('allocateTask', () => {
beforeAll(() => {
advanceTo(new Date('2022-01-01T07:00:00'))
jest
.spyOn(Date, 'now')
.mockImplementation(() => new Date('2022-01-01T07:00:00').getTime())
})

it('should allocate a task if there is a gap between schedules', () => {
Expand Down Expand Up @@ -140,4 +136,8 @@ describe('allocateTask', () => {
}),
).toThrowError(DeadlineExceededException)
})

afterAll(() => {
jest.spyOn(Date, 'now').mockRestore()
})
})

0 comments on commit a30381e

Please sign in to comment.