Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 88ab4ab

Browse files
committed
use jest setSystemTime
1 parent 54f9b52 commit 88ab4ab

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

test/utils/DateUtils-test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@ describe("formatSeconds", () => {
4444
});
4545

4646
describe("formatRelativeTime", () => {
47-
let dateSpy: jest.SpyInstance<number, []>;
47+
jest.useFakeTimers();
48+
4849
beforeAll(() => {
49-
dateSpy = jest
50-
.spyOn(global.Date, "now")
51-
// Tuesday, 2 November 2021 11:18:03 UTC
52-
.mockImplementation(() => 1635851883000);
50+
// Tuesday, 2 November 2021 11:18:03 UTC
51+
jest.setSystemTime(1635851883000);
5352
});
5453

5554
afterAll(() => {
56-
dateSpy.mockRestore();
55+
jest.setSystemTime(jest.getRealSystemTime());
56+
jest.useRealTimers();
5757
});
5858

5959
it("returns hour format for events created in the same day", () => {

0 commit comments

Comments
 (0)