From 68c5a55eedb2b0752aa0d702678fd9636cae7169 Mon Sep 17 00:00:00 2001 From: Kerry Date: Tue, 19 Apr 2022 14:44:15 +0200 Subject: [PATCH] use fake timers and restore mocks in MatrixClientPeg test (#8356) Signed-off-by: Kerry Archibald --- test/MatrixClientPeg-test.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/MatrixClientPeg-test.ts b/test/MatrixClientPeg-test.ts index f3f6826c15..13a298d5a5 100644 --- a/test/MatrixClientPeg-test.ts +++ b/test/MatrixClientPeg-test.ts @@ -17,10 +17,12 @@ limitations under the License. import { advanceDateAndTime, stubClient } from "./test-utils"; import { MatrixClientPeg as peg } from "../src/MatrixClientPeg"; +jest.useFakeTimers(); + describe("MatrixClientPeg", () => { afterEach(() => { localStorage.clear(); - advanceDateAndTime(0); + jest.restoreAllMocks(); }); it("setJustRegisteredUserId", () => { @@ -32,7 +34,7 @@ describe("MatrixClientPeg", () => { expect(peg.userRegisteredWithinLastHours(0)).toBe(false); expect(peg.userRegisteredWithinLastHours(1)).toBe(true); expect(peg.userRegisteredWithinLastHours(24)).toBe(true); - advanceDateAndTime(1 * 60 * 60 * 1000); + advanceDateAndTime(1 * 60 * 60 * 1000 + 1); expect(peg.userRegisteredWithinLastHours(0)).toBe(false); expect(peg.userRegisteredWithinLastHours(1)).toBe(false); expect(peg.userRegisteredWithinLastHours(24)).toBe(true); @@ -50,7 +52,7 @@ describe("MatrixClientPeg", () => { expect(peg.userRegisteredWithinLastHours(0)).toBe(false); expect(peg.userRegisteredWithinLastHours(1)).toBe(false); expect(peg.userRegisteredWithinLastHours(24)).toBe(false); - advanceDateAndTime(1 * 60 * 60 * 1000); + advanceDateAndTime(1 * 60 * 60 * 1000 + 1); expect(peg.userRegisteredWithinLastHours(0)).toBe(false); expect(peg.userRegisteredWithinLastHours(1)).toBe(false); expect(peg.userRegisteredWithinLastHours(24)).toBe(false);