1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-07-31 15:24:23 +03:00

Make more of the code conform to Strict TSC (#2756)

This commit is contained in:
Michael Telatynski
2022-10-14 15:57:08 +01:00
committed by GitHub
parent f70f6db926
commit 12a4d2a749
33 changed files with 675 additions and 454 deletions

View File

@ -201,7 +201,7 @@ describe("MatrixClient events", function() {
});
client!.on(RoomEvent.Timeline, function(event, room) {
timelineFireCount++;
expect(room.roomId).toEqual("!erufh:bar");
expect(room?.roomId).toEqual("!erufh:bar");
});
client!.on(RoomEvent.Name, function(room) {
roomNameInvokeCount++;

View File

@ -368,7 +368,7 @@ describe("MatrixClient event timelines", function() {
expect(tl!.getEvents().length).toEqual(4);
for (let i = 0; i < 4; i++) {
expect(tl!.getEvents()[i].event).toEqual(EVENTS[i]);
expect(tl!.getEvents()[i]?.sender.name).toEqual(userName);
expect(tl!.getEvents()[i]?.sender?.name).toEqual(userName);
}
expect(tl!.getPaginationToken(EventTimeline.BACKWARDS))
.toEqual("start_token");
@ -406,7 +406,7 @@ describe("MatrixClient event timelines", function() {
}).then(function(tl) {
expect(tl!.getEvents().length).toEqual(2);
expect(tl!.getEvents()[1].event).toEqual(EVENTS[0]);
expect(tl!.getEvents()[1]?.sender.name).toEqual(userName);
expect(tl!.getEvents()[1]?.sender?.name).toEqual(userName);
expect(tl!.getPaginationToken(EventTimeline.BACKWARDS))
.toEqual("f_1_1");
// expect(tl.getPaginationToken(EventTimeline.FORWARDS))
@ -767,8 +767,8 @@ describe("MatrixClient event timelines", function() {
httpBackend = testClient.httpBackend;
await startClient(httpBackend, client);
const room = client.getRoom(roomId);
const timelineSet = room.getTimelineSets()[0];
const room = client.getRoom(roomId)!;
const timelineSet = room.getTimelineSets()[0]!;
await expect(client.getLatestTimeline(timelineSet)).rejects.toBeTruthy();
});
@ -786,7 +786,7 @@ describe("MatrixClient event timelines", function() {
httpBackend = testClient.httpBackend;
return startClient(httpBackend, client).then(() => {
const room = client.getRoom(roomId);
const room = client.getRoom(roomId)!;
const timelineSet = room.getTimelineSets()[0];
expect(client.getLatestTimeline(timelineSet)).rejects.toBeFalsy();
});
@ -849,7 +849,7 @@ describe("MatrixClient event timelines", function() {
expect(tl!.getEvents().length).toEqual(4);
for (let i = 0; i < 4; i++) {
expect(tl!.getEvents()[i].event).toEqual(EVENTS[i]);
expect(tl!.getEvents()[i]?.sender.name).toEqual(userName);
expect(tl!.getEvents()[i]?.sender?.name).toEqual(userName);
}
expect(tl!.getPaginationToken(EventTimeline.BACKWARDS))
.toEqual("start_token");
@ -1129,8 +1129,8 @@ describe("MatrixClient event timelines", function() {
});
it("should allow fetching all threads", async function() {
const room = client.getRoom(roomId);
const timelineSets = await room?.createThreadsTimelineSets();
const room = client.getRoom(roomId)!;
const timelineSets = await room.createThreadsTimelineSets();
expect(timelineSets).not.toBeNull();
respondToThreads();
respondToThreads();
@ -1185,14 +1185,14 @@ describe("MatrixClient event timelines", function() {
});
it("should allow fetching all threads", async function() {
const room = client.getRoom(roomId);
const room = client.getRoom(roomId)!;
respondToFilter();
respondToSync();
respondToFilter();
respondToSync();
const timelineSetsPromise = room?.createThreadsTimelineSets();
const timelineSetsPromise = room.createThreadsTimelineSets();
expect(timelineSetsPromise).not.toBeNull();
await flushHttp(timelineSetsPromise!);
respondToFilter();
@ -1218,7 +1218,7 @@ describe("MatrixClient event timelines", function() {
const [allThreads] = timelineSets!;
respondToThreads().check((request) => {
expect(request.queryParams.filter).toEqual(JSON.stringify({
expect(request.queryParams?.filter).toEqual(JSON.stringify({
"lazy_load_members": true,
}));
});
@ -1244,7 +1244,7 @@ describe("MatrixClient event timelines", function() {
state: [],
next_batch: null,
}).check((request) => {
expect(request.queryParams.from).toEqual(RANDOM_TOKEN);
expect(request.queryParams?.from).toEqual(RANDOM_TOKEN);
});
allThreads.getLiveTimeline().setPaginationToken(RANDOM_TOKEN, Direction.Backward);

View File

@ -160,8 +160,8 @@ describe("MatrixClient room timelines", function() {
expect(room.timeline[1].status).toEqual(EventStatus.SENDING);
// check member
const member = room.timeline[1].sender;
expect(member.userId).toEqual(userId);
expect(member.name).toEqual(userName);
expect(member?.userId).toEqual(userId);
expect(member?.name).toEqual(userName);
httpBackend!.flush("/sync", 1).then(function() {
done();
@ -327,11 +327,11 @@ describe("MatrixClient room timelines", function() {
client!.scrollback(room).then(function() {
expect(room.timeline.length).toEqual(5);
const joinMsg = room.timeline[0];
expect(joinMsg.sender.name).toEqual("Old Alice");
expect(joinMsg.sender?.name).toEqual("Old Alice");
const oldMsg = room.timeline[1];
expect(oldMsg.sender.name).toEqual("Old Alice");
expect(oldMsg.sender?.name).toEqual("Old Alice");
const newMsg = room.timeline[3];
expect(newMsg.sender.name).toEqual(userName);
expect(newMsg.sender?.name).toEqual(userName);
// still have a sync to flush
httpBackend!.flush("/sync", 1).then(() => {
@ -468,8 +468,8 @@ describe("MatrixClient room timelines", function() {
]).then(function() {
const preNameEvent = room.timeline[room.timeline.length - 3];
const postNameEvent = room.timeline[room.timeline.length - 1];
expect(preNameEvent.sender.name).toEqual(userName);
expect(postNameEvent.sender.name).toEqual("New Name");
expect(preNameEvent.sender?.name).toEqual(userName);
expect(postNameEvent.sender?.name).toEqual("New Name");
});
});
});

View File

@ -1276,9 +1276,9 @@ describe("MatrixClient syncing", () => {
client!.on(RoomEvent.TimelineReset, (room) => {
resetCallCount++;
const tl = room.getLiveTimeline();
expect(tl.getEvents().length).toEqual(0);
const tok = tl.getPaginationToken(EventTimeline.BACKWARDS);
const tl = room?.getLiveTimeline();
expect(tl?.getEvents().length).toEqual(0);
const tok = tl?.getPaginationToken(EventTimeline.BACKWARDS);
expect(tok).toEqual("newerTok");
});