use fake timers and restore mocks in MatrixClientPeg test (#8356)
Signed-off-by: Kerry Archibald <kerrya@element.io>
This commit is contained in:
parent
80c1fad088
commit
68c5a55eed
1 changed files with 5 additions and 3 deletions
|
@ -17,10 +17,12 @@ limitations under the License.
|
||||||
import { advanceDateAndTime, stubClient } from "./test-utils";
|
import { advanceDateAndTime, stubClient } from "./test-utils";
|
||||||
import { MatrixClientPeg as peg } from "../src/MatrixClientPeg";
|
import { MatrixClientPeg as peg } from "../src/MatrixClientPeg";
|
||||||
|
|
||||||
|
jest.useFakeTimers();
|
||||||
|
|
||||||
describe("MatrixClientPeg", () => {
|
describe("MatrixClientPeg", () => {
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
advanceDateAndTime(0);
|
jest.restoreAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("setJustRegisteredUserId", () => {
|
it("setJustRegisteredUserId", () => {
|
||||||
|
@ -32,7 +34,7 @@ describe("MatrixClientPeg", () => {
|
||||||
expect(peg.userRegisteredWithinLastHours(0)).toBe(false);
|
expect(peg.userRegisteredWithinLastHours(0)).toBe(false);
|
||||||
expect(peg.userRegisteredWithinLastHours(1)).toBe(true);
|
expect(peg.userRegisteredWithinLastHours(1)).toBe(true);
|
||||||
expect(peg.userRegisteredWithinLastHours(24)).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(0)).toBe(false);
|
||||||
expect(peg.userRegisteredWithinLastHours(1)).toBe(false);
|
expect(peg.userRegisteredWithinLastHours(1)).toBe(false);
|
||||||
expect(peg.userRegisteredWithinLastHours(24)).toBe(true);
|
expect(peg.userRegisteredWithinLastHours(24)).toBe(true);
|
||||||
|
@ -50,7 +52,7 @@ describe("MatrixClientPeg", () => {
|
||||||
expect(peg.userRegisteredWithinLastHours(0)).toBe(false);
|
expect(peg.userRegisteredWithinLastHours(0)).toBe(false);
|
||||||
expect(peg.userRegisteredWithinLastHours(1)).toBe(false);
|
expect(peg.userRegisteredWithinLastHours(1)).toBe(false);
|
||||||
expect(peg.userRegisteredWithinLastHours(24)).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(0)).toBe(false);
|
||||||
expect(peg.userRegisteredWithinLastHours(1)).toBe(false);
|
expect(peg.userRegisteredWithinLastHours(1)).toBe(false);
|
||||||
expect(peg.userRegisteredWithinLastHours(24)).toBe(false);
|
expect(peg.userRegisteredWithinLastHours(24)).toBe(false);
|
||||||
|
|
Loading…
Reference in a new issue