Make more code conform to strict null checks (#10219
* Make more code conform to strict null checks * Fix types * Fix tests * Fix remaining test assertions * Iterate PR
This commit is contained in:
parent
4c79ecf141
commit
76b82b4b2b
130 changed files with 603 additions and 603 deletions
|
@ -3,7 +3,7 @@
|
|||
exports[`<EmbeddedPage /> should render nothing if no url given 1`] = `
|
||||
<DocumentFragment>
|
||||
<div
|
||||
class="undefined undefined_guest"
|
||||
class="undefined_guest"
|
||||
>
|
||||
<div
|
||||
class="undefined_body"
|
||||
|
@ -15,7 +15,7 @@ exports[`<EmbeddedPage /> should render nothing if no url given 1`] = `
|
|||
exports[`<EmbeddedPage /> should show error if unable to load 1`] = `
|
||||
<DocumentFragment>
|
||||
<div
|
||||
class="undefined undefined_guest"
|
||||
class="undefined_guest"
|
||||
>
|
||||
<div
|
||||
class="undefined_body"
|
||||
|
@ -29,7 +29,7 @@ exports[`<EmbeddedPage /> should show error if unable to load 1`] = `
|
|||
exports[`<EmbeddedPage /> should translate _t strings 1`] = `
|
||||
<DocumentFragment>
|
||||
<div
|
||||
class="undefined undefined_guest"
|
||||
class="undefined_guest"
|
||||
>
|
||||
<div
|
||||
class="undefined_body"
|
||||
|
|
|
@ -39,7 +39,7 @@ describe("InteractiveAuthDialog", function () {
|
|||
|
||||
beforeEach(function () {
|
||||
jest.clearAllMocks();
|
||||
mockClient.credentials = null;
|
||||
mockClient.credentials = { userId: null };
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
|
|
|
@ -97,7 +97,7 @@ function mockClient({
|
|||
);
|
||||
return Promise.resolve({
|
||||
results: results.slice(0, limit ?? +Infinity),
|
||||
limited: limit && limit < results.length,
|
||||
limited: !!limit && limit < results.length,
|
||||
});
|
||||
});
|
||||
cli.getProfileInfo = jest.fn(async (userId) => {
|
||||
|
|
|
@ -74,8 +74,8 @@ describe("<UserSettingsDialog />", () => {
|
|||
});
|
||||
|
||||
const getActiveTabLabel = (container: Element) =>
|
||||
container.querySelector(".mx_TabbedView_tabLabel_active").textContent;
|
||||
const getActiveTabHeading = (container: Element) => container.querySelector(".mx_SettingsTab_heading").textContent;
|
||||
container.querySelector(".mx_TabbedView_tabLabel_active")?.textContent;
|
||||
const getActiveTabHeading = (container: Element) => container.querySelector(".mx_SettingsTab_heading")?.textContent;
|
||||
|
||||
it("should render general settings tab when no initialTabId", () => {
|
||||
const { container } = render(getComponent());
|
||||
|
|
|
@ -146,7 +146,7 @@ describe("<LocationShareMenu />", () => {
|
|||
const setLocationGeolocate = () => {
|
||||
// get the callback LocationShareMenu registered for geolocate
|
||||
expect(mocked(mockGeolocate.on)).toHaveBeenCalledWith("geolocate", expect.any(Function));
|
||||
const [, onGeolocateCallback] = mocked(mockGeolocate.on).mock.calls.find(([event]) => event === "geolocate");
|
||||
const [, onGeolocateCallback] = mocked(mockGeolocate.on).mock.calls.find(([event]) => event === "geolocate")!;
|
||||
|
||||
// set the location
|
||||
onGeolocateCallback(position);
|
||||
|
@ -155,7 +155,7 @@ describe("<LocationShareMenu />", () => {
|
|||
const setLocationClick = () => {
|
||||
// get the callback LocationShareMenu registered for geolocate
|
||||
expect(mocked(mockMap.on)).toHaveBeenCalledWith("click", expect.any(Function));
|
||||
const [, onMapClickCallback] = mocked(mockMap.on).mock.calls.find(([event]) => event === "click");
|
||||
const [, onMapClickCallback] = mocked(mockMap.on).mock.calls.find(([event]) => event === "click")!;
|
||||
|
||||
const event = {
|
||||
lngLat: { lng: position.coords.longitude, lat: position.coords.latitude },
|
||||
|
|
|
@ -51,6 +51,6 @@ describe("<LocationViewDialog />", () => {
|
|||
// @ts-ignore cheat assignment to property
|
||||
selfShareEvent.sender = member;
|
||||
const { container } = getComponent({ mxEvent: selfShareEvent });
|
||||
expect(container.querySelector(".mx_BaseAvatar_image").getAttribute("title")).toEqual(userId);
|
||||
expect(container.querySelector(".mx_BaseAvatar_image")?.getAttribute("title")).toEqual(userId);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -28,7 +28,7 @@ describe("ReadReceiptGroup", () => {
|
|||
expect(readReceiptTooltip(["Alice", "Bob", "Charlie"], true)).toEqual("Alice, Bob, Charlie and more");
|
||||
expect(readReceiptTooltip(["Alice", "Bob"], true)).toEqual("Alice, Bob and more");
|
||||
expect(readReceiptTooltip(["Alice"], true)).toEqual("Alice and more");
|
||||
expect(readReceiptTooltip([], false)).toEqual(null);
|
||||
expect(readReceiptTooltip([], false)).toBeUndefined();
|
||||
});
|
||||
it("returns a pretty list without hasMore", () => {
|
||||
expect(readReceiptTooltip(["Alice", "Bob", "Charlie", "Dan", "Eve"], false)).toEqual(
|
||||
|
@ -40,7 +40,7 @@ describe("ReadReceiptGroup", () => {
|
|||
expect(readReceiptTooltip(["Alice", "Bob", "Charlie"], false)).toEqual("Alice, Bob and Charlie");
|
||||
expect(readReceiptTooltip(["Alice", "Bob"], false)).toEqual("Alice and Bob");
|
||||
expect(readReceiptTooltip(["Alice"], false)).toEqual("Alice");
|
||||
expect(readReceiptTooltip([], false)).toEqual(null);
|
||||
expect(readReceiptTooltip([], false)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
describe("AvatarPosition", () => {
|
||||
|
|
|
@ -281,7 +281,7 @@ describe("<SendMessageComposer/>", () => {
|
|||
|
||||
it("correctly sends a message", () => {
|
||||
mocked(doMaybeLocalRoomAction).mockImplementation(
|
||||
<T extends {}>(roomId: string, fn: (actualRoomId: string) => Promise<T>, _client?: MatrixClient) => {
|
||||
<T,>(roomId: string, fn: (actualRoomId: string) => Promise<T>, _client?: MatrixClient) => {
|
||||
return fn(roomId);
|
||||
},
|
||||
);
|
||||
|
@ -300,7 +300,7 @@ describe("<SendMessageComposer/>", () => {
|
|||
|
||||
it("shows chat effects on message sending", () => {
|
||||
mocked(doMaybeLocalRoomAction).mockImplementation(
|
||||
<T extends {}>(roomId: string, fn: (actualRoomId: string) => Promise<T>, _client?: MatrixClient) => {
|
||||
<T,>(roomId: string, fn: (actualRoomId: string) => Promise<T>, _client?: MatrixClient) => {
|
||||
return fn(roomId);
|
||||
},
|
||||
);
|
||||
|
@ -321,7 +321,7 @@ describe("<SendMessageComposer/>", () => {
|
|||
|
||||
it("not to send chat effects on message sending for threads", () => {
|
||||
mocked(doMaybeLocalRoomAction).mockImplementation(
|
||||
<T extends {}>(roomId: string, fn: (actualRoomId: string) => Promise<T>, _client?: MatrixClient) => {
|
||||
<T,>(roomId: string, fn: (actualRoomId: string) => Promise<T>, _client?: MatrixClient) => {
|
||||
return fn(roomId);
|
||||
},
|
||||
);
|
||||
|
|
|
@ -25,6 +25,7 @@ import { VoiceRecording } from "../../../../src/audio/VoiceRecording";
|
|||
import { doMaybeLocalRoomAction } from "../../../../src/utils/local-room";
|
||||
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
||||
import { IUpload } from "../../../../src/audio/VoiceMessageRecording";
|
||||
import { RoomPermalinkCreator } from "../../../../src/utils/permalinks/Permalinks";
|
||||
|
||||
jest.mock("../../../../src/utils/local-room", () => ({
|
||||
doMaybeLocalRoomAction: jest.fn(),
|
||||
|
@ -43,10 +44,12 @@ describe("<VoiceRecordComposerTile/>", () => {
|
|||
} as unknown as MatrixClient;
|
||||
MatrixClientPeg.get = () => mockClient;
|
||||
|
||||
const room = {
|
||||
roomId,
|
||||
} as unknown as Room;
|
||||
const props = {
|
||||
room: {
|
||||
roomId,
|
||||
} as unknown as Room,
|
||||
room,
|
||||
permalinkCreator: new RoomPermalinkCreator(room),
|
||||
};
|
||||
mockUpload = {
|
||||
mxc: "mxc://example.com/voice",
|
||||
|
@ -66,7 +69,7 @@ describe("<VoiceRecordComposerTile/>", () => {
|
|||
});
|
||||
|
||||
mocked(doMaybeLocalRoomAction).mockImplementation(
|
||||
<T extends {}>(roomId: string, fn: (actualRoomId: string) => Promise<T>, _client?: MatrixClient) => {
|
||||
<T,>(roomId: string, fn: (actualRoomId: string) => Promise<T>, _client?: MatrixClient) => {
|
||||
return fn(roomId);
|
||||
},
|
||||
);
|
||||
|
|
|
@ -42,6 +42,7 @@ describe("<CurrentDeviceSection />", () => {
|
|||
isLoading: false,
|
||||
isSigningOut: false,
|
||||
otherSessionsCount: 1,
|
||||
setPushNotifications: jest.fn(),
|
||||
};
|
||||
|
||||
const getComponent = (props = {}): React.ReactElement => <CurrentDeviceSection {...defaultProps} {...props} />;
|
||||
|
|
|
@ -47,7 +47,7 @@ describe("AdvancedRoomSettingsTab", () => {
|
|||
mocked(dis.dispatch).mockReset();
|
||||
mocked(room.findPredecessor).mockImplementation((msc3946: boolean) =>
|
||||
msc3946
|
||||
? { roomId: "old_room_id_via_predecessor", eventId: null }
|
||||
? { roomId: "old_room_id_via_predecessor" }
|
||||
: { roomId: "old_room_id", eventId: "tombstone_event_id" },
|
||||
);
|
||||
});
|
||||
|
@ -136,7 +136,7 @@ describe("AdvancedRoomSettingsTab", () => {
|
|||
fireEvent.click(link);
|
||||
expect(dis.dispatch).toHaveBeenCalledWith({
|
||||
action: Action.ViewRoom,
|
||||
event_id: null,
|
||||
event_id: undefined,
|
||||
room_id: "old_room_id_via_predecessor",
|
||||
metricsTrigger: "WebPredecessorSettings",
|
||||
metricsViaKeyboard: false,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue