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

Commit 68c5a55

Browse files
author
Kerry
authored
use fake timers and restore mocks in MatrixClientPeg test (#8356)
Signed-off-by: Kerry Archibald <[email protected]>
1 parent 80c1fad commit 68c5a55

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

test/MatrixClientPeg-test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ limitations under the License.
1717
import { advanceDateAndTime, stubClient } from "./test-utils";
1818
import { MatrixClientPeg as peg } from "../src/MatrixClientPeg";
1919

20+
jest.useFakeTimers();
21+
2022
describe("MatrixClientPeg", () => {
2123
afterEach(() => {
2224
localStorage.clear();
23-
advanceDateAndTime(0);
25+
jest.restoreAllMocks();
2426
});
2527

2628
it("setJustRegisteredUserId", () => {
@@ -32,7 +34,7 @@ describe("MatrixClientPeg", () => {
3234
expect(peg.userRegisteredWithinLastHours(0)).toBe(false);
3335
expect(peg.userRegisteredWithinLastHours(1)).toBe(true);
3436
expect(peg.userRegisteredWithinLastHours(24)).toBe(true);
35-
advanceDateAndTime(1 * 60 * 60 * 1000);
37+
advanceDateAndTime(1 * 60 * 60 * 1000 + 1);
3638
expect(peg.userRegisteredWithinLastHours(0)).toBe(false);
3739
expect(peg.userRegisteredWithinLastHours(1)).toBe(false);
3840
expect(peg.userRegisteredWithinLastHours(24)).toBe(true);
@@ -50,7 +52,7 @@ describe("MatrixClientPeg", () => {
5052
expect(peg.userRegisteredWithinLastHours(0)).toBe(false);
5153
expect(peg.userRegisteredWithinLastHours(1)).toBe(false);
5254
expect(peg.userRegisteredWithinLastHours(24)).toBe(false);
53-
advanceDateAndTime(1 * 60 * 60 * 1000);
55+
advanceDateAndTime(1 * 60 * 60 * 1000 + 1);
5456
expect(peg.userRegisteredWithinLastHours(0)).toBe(false);
5557
expect(peg.userRegisteredWithinLastHours(1)).toBe(false);
5658
expect(peg.userRegisteredWithinLastHours(24)).toBe(false);

0 commit comments

Comments
 (0)