Use MatrixClientPeg::safeGet for strict typing (#10989)

This commit is contained in:
Michael Telatynski 2023-06-21 17:29:44 +01:00 committed by GitHub
parent d64018ce26
commit 9b5b053148
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
60 changed files with 225 additions and 203 deletions

View file

@ -81,13 +81,13 @@ describe("Unread", () => {
it("returns false for an event without a renderer", () => {
mocked(haveRendererForEvent).mockReturnValue(false);
expect(eventTriggersUnreadCount(client, alicesMessage)).toBe(false);
expect(haveRendererForEvent).toHaveBeenCalledWith(alicesMessage, false);
expect(haveRendererForEvent).toHaveBeenCalledWith(alicesMessage, client, false);
});
it("returns true for an event with a renderer", () => {
mocked(haveRendererForEvent).mockReturnValue(true);
expect(eventTriggersUnreadCount(client, alicesMessage)).toBe(true);
expect(haveRendererForEvent).toHaveBeenCalledWith(alicesMessage, false);
expect(haveRendererForEvent).toHaveBeenCalledWith(alicesMessage, client, false);
});
it("returns false for beacon locations", () => {

View file

@ -29,6 +29,7 @@ import RoomContext, { TimelineRenderingType } from "../../../src/contexts/RoomCo
import DMRoomMap from "../../../src/utils/DMRoomMap";
import * as TestUtilsMatrix from "../../test-utils";
import {
createTestClient,
getMockClientWithEventEmitter,
makeBeaconInfoEvent,
mockClientMethodsEvents,
@ -773,16 +774,17 @@ describe("shouldFormContinuation", () => {
msg: "And here's another message in the main timeline after the thread root",
});
expect(shouldFormContinuation(message1, message2, false)).toEqual(true);
expect(shouldFormContinuation(message2, threadRoot, false)).toEqual(true);
expect(shouldFormContinuation(threadRoot, message3, false)).toEqual(true);
const client = createTestClient();
expect(shouldFormContinuation(message1, message2, client, false)).toEqual(true);
expect(shouldFormContinuation(message2, threadRoot, client, false)).toEqual(true);
expect(shouldFormContinuation(threadRoot, message3, client, false)).toEqual(true);
const thread = {
length: 1,
replyToEvent: {},
} as unknown as Thread;
jest.spyOn(threadRoot, "getThread").mockReturnValue(thread);
expect(shouldFormContinuation(message2, threadRoot, false)).toEqual(false);
expect(shouldFormContinuation(threadRoot, message3, false)).toEqual(false);
expect(shouldFormContinuation(message2, threadRoot, client, false)).toEqual(false);
expect(shouldFormContinuation(threadRoot, message3, client, false)).toEqual(false);
});
});

View file

@ -28,7 +28,7 @@ jest.mock("../../../../../src/SecurityManager", () => ({
describe("CreateKeyBackupDialog", () => {
beforeEach(() => {
MatrixClientPeg.get = () => createTestClient();
MatrixClientPeg.safeGet = MatrixClientPeg.get = () => createTestClient();
});
it("should display the spinner when creating backup", () => {
@ -42,7 +42,7 @@ describe("CreateKeyBackupDialog", () => {
it("should display the error message when backup creation failed", async () => {
const matrixClient = createTestClient();
mocked(matrixClient.scheduleAllGroupSessionsForBackup).mockRejectedValue("my error");
MatrixClientPeg.get = () => matrixClient;
MatrixClientPeg.safeGet = MatrixClientPeg.get = () => matrixClient;
const { asFragment } = render(<CreateKeyBackupDialog onFinished={jest.fn()} />);

View file

@ -95,8 +95,8 @@ describe("<RoomPreviewBar />", () => {
beforeEach(() => {
stubClient();
MatrixClientPeg.get().getUserId = jest.fn().mockReturnValue(userId);
MatrixClientPeg.get().getSafeUserId = jest.fn().mockReturnValue(userId);
MatrixClientPeg.get()!.getUserId = jest.fn().mockReturnValue(userId);
MatrixClientPeg.get()!.getSafeUserId = jest.fn().mockReturnValue(userId);
MatrixClientPeg.safeGet().getUserId = jest.fn().mockReturnValue(userId);
MatrixClientPeg.safeGet().getSafeUserId = jest.fn().mockReturnValue(userId);
});