Skip to content

Commit d4e1c9f

Browse files
committed
2 parents 3639083 + b1d7788 commit d4e1c9f

19 files changed

+386
-152
lines changed

.eslintrc.js

-3
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ module.exports = {
6969
// TODO: There are many tests with invalid expects that should be fixed,
7070
// https://github.com/matrix-org/matrix-js-sdk/issues/2976
7171
"jest/valid-expect": "off",
72-
// TODO: There are many cases to refactor away,
73-
// https://github.com/matrix-org/matrix-js-sdk/issues/2978
74-
"jest/no-conditional-expect": "off",
7572
// Also treat "oldBackendOnly" as a test function.
7673
// Used in some crypto tests.
7774
"jest/no-standalone-expect": [

CHANGELOG.md

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ Changes in [23.4.0](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v23
77
* Polls: count undecryptable poll relations ([\#3163](https://github.com/matrix-org/matrix-js-sdk/pull/3163)). Contributed by @kerryarchibald.
88

99
## 🐛 Bug Fixes
10-
* Fix spec compliance issue around encrypted `m.relates_to` ([\#3178](https://github.com/matrix-org/matrix-js-sdk/pull/3178)).
11-
* Fix reactions in threads sometimes causing stuck notifications ([\#3146](https://github.com/matrix-org/matrix-js-sdk/pull/3146)). Fixes vector-im/element-web#24000. Contributed by @justjanne.
1210
* Better type guard parseTopicContent ([\#3165](https://github.com/matrix-org/matrix-js-sdk/pull/3165)). Fixes matrix-org/element-web-rageshakes#20177 and matrix-org/element-web-rageshakes#20178.
1311
* Fix a bug where events in encrypted rooms would sometimes erroneously increment the total unread counter after being processed locally. ([\#3130](https://github.com/matrix-org/matrix-js-sdk/pull/3130)). Fixes vector-im/element-web#24448. Contributed by @Half-Shot.
1412
* Stop the ICE disconnected timer on call terminate ([\#3147](https://github.com/matrix-org/matrix-js-sdk/pull/3147)).

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
"debug": "^4.3.4",
102102
"docdash": "^2.0.0",
103103
"domexception": "^4.0.0",
104-
"eslint": "8.34.0",
104+
"eslint": "8.35.0",
105105
"eslint-config-google": "^0.14.0",
106106
"eslint-config-prettier": "^8.5.0",
107107
"eslint-import-resolver-typescript": "^3.5.1",

spec/integ/matrix-client-opts.spec.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,10 @@ describe("MatrixClient opts", function () {
157157
error: "Ruh roh",
158158
}),
159159
);
160-
try {
161-
await Promise.all([
162-
expect(client.sendTextMessage("!foo:bar", "a body", "txn1")).rejects.toThrow(),
163-
httpBackend.flush("/txn1", 1),
164-
]);
165-
} catch (err) {
166-
expect((<MatrixError>err).errcode).toEqual("M_SOMETHING");
167-
}
160+
161+
await expect(
162+
Promise.all([client.sendTextMessage("!foo:bar", "a body", "txn1"), httpBackend.flush("/txn1", 1)]),
163+
).rejects.toThrow("MatrixError: [500] Unknown message");
168164
});
169165

170166
it("shouldn't queue events", async () => {

spec/integ/sliding-sync-sdk.spec.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -891,11 +891,9 @@ describe("SlidingSyncSdk", () => {
891891
const evType = ev.getType();
892892
expect(seen[evType]).toBeFalsy();
893893
seen[evType] = true;
894-
if (evType === "m.key.verification.start" || evType === "m.key.verification.request") {
895-
expect(ev.isCancelled()).toEqual(true);
896-
} else {
897-
expect(ev.isCancelled()).toEqual(false);
898-
}
894+
expect(ev.isCancelled()).toEqual(
895+
evType === "m.key.verification.start" || evType === "m.key.verification.request",
896+
);
899897
});
900898
ext.onResponse({
901899
next_batch: "45678",

spec/unit/NamespacedValue.spec.ts

+2-14
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,7 @@ describe("NamespacedValue", () => {
4646
});
4747

4848
it("should not permit falsey values for both parts", () => {
49-
try {
50-
new UnstableValue(null!, null!);
51-
// noinspection ExceptionCaughtLocallyJS
52-
throw new Error("Failed to fail");
53-
} catch (e) {
54-
expect((<Error>e).message).toBe("One of stable or unstable values must be supplied");
55-
}
49+
expect(() => new UnstableValue(null!, null!)).toThrow("One of stable or unstable values must be supplied");
5650
});
5751
});
5852

@@ -72,12 +66,6 @@ describe("UnstableValue", () => {
7266
});
7367

7468
it("should not permit falsey unstable values", () => {
75-
try {
76-
new UnstableValue("stable", null!);
77-
// noinspection ExceptionCaughtLocallyJS
78-
throw new Error("Failed to fail");
79-
} catch (e) {
80-
expect((<Error>e).message).toBe("Unstable value must be supplied");
81-
}
69+
expect(() => new UnstableValue("stable", null!)).toThrow("Unstable value must be supplied");
8270
});
8371
});

spec/unit/crypto/CrossSigningInfo.spec.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,10 @@ describe("CrossSigningInfo.getCrossSigningKey", function () {
102102
const info = new CrossSigningInfo(userId, { getCrossSigningKey }, { getCrossSigningKeyCache });
103103
const [pubKey] = await info.getCrossSigningKey(type, masterKeyPub);
104104
expect(pubKey).toEqual(masterKeyPub);
105-
expect(getCrossSigningKeyCache.mock.calls.length).toBe(shouldCache ? 1 : 0);
105+
expect(getCrossSigningKeyCache).toHaveBeenCalledTimes(shouldCache ? 1 : 0);
106106
if (shouldCache) {
107-
expect(getCrossSigningKeyCache.mock.calls[0][0]).toBe(type);
107+
// eslint-disable-next-line jest/no-conditional-expect
108+
expect(getCrossSigningKeyCache).toHaveBeenLastCalledWith(type, expect.any(String));
108109
}
109110
},
110111
);
@@ -115,10 +116,10 @@ describe("CrossSigningInfo.getCrossSigningKey", function () {
115116
const info = new CrossSigningInfo(userId, { getCrossSigningKey }, { storeCrossSigningKeyCache });
116117
const [pubKey] = await info.getCrossSigningKey(type, masterKeyPub);
117118
expect(pubKey).toEqual(masterKeyPub);
118-
expect(storeCrossSigningKeyCache.mock.calls.length).toEqual(shouldCache ? 1 : 0);
119+
expect(storeCrossSigningKeyCache).toHaveBeenCalledTimes(shouldCache ? 1 : 0);
119120
if (shouldCache) {
120-
expect(storeCrossSigningKeyCache.mock.calls[0][0]).toBe(type);
121-
expect(storeCrossSigningKeyCache.mock.calls[0][1]).toBe(testKey);
121+
// eslint-disable-next-line jest/no-conditional-expect
122+
expect(storeCrossSigningKeyCache).toHaveBeenLastCalledWith(type, testKey);
122123
}
123124
});
124125

spec/unit/crypto/backup.spec.ts

+2
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ describe("MegolmBackup", function () {
456456
client.http.authedRequest = function (method, path, queryParams, data, opts): any {
457457
++numCalls;
458458
expect(numCalls).toBeLessThanOrEqual(2);
459+
/* eslint-disable jest/no-conditional-expect */
459460
if (numCalls === 1) {
460461
expect(method).toBe("POST");
461462
expect(path).toBe("/room_keys/version");
@@ -482,6 +483,7 @@ describe("MegolmBackup", function () {
482483
reject(new Error("authedRequest called too many times"));
483484
return Promise.resolve({});
484485
}
486+
/* eslint-enable jest/no-conditional-expect */
485487
};
486488
}),
487489
client.createKeyBackupVersion({

spec/unit/matrix-client.spec.ts

+13
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@ describe("MatrixClient", function () {
725725
getMyMembership: () => "join",
726726
currentState: {
727727
getStateEvents: (eventType, stateKey) => {
728+
/* eslint-disable jest/no-conditional-expect */
728729
if (eventType === EventType.RoomCreate) {
729730
expect(stateKey).toEqual("");
730731
return new MatrixEvent({
@@ -743,6 +744,7 @@ describe("MatrixClient", function () {
743744
} else {
744745
throw new Error("Unexpected event type or state key");
745746
}
747+
/* eslint-enable jest/no-conditional-expect */
746748
},
747749
} as Room["currentState"],
748750
} as unknown as Room;
@@ -785,6 +787,7 @@ describe("MatrixClient", function () {
785787
getMyMembership: () => "join",
786788
currentState: {
787789
getStateEvents: (eventType, stateKey) => {
790+
/* eslint-disable jest/no-conditional-expect */
788791
if (eventType === EventType.RoomCreate) {
789792
expect(stateKey).toEqual("");
790793
return new MatrixEvent({
@@ -803,6 +806,7 @@ describe("MatrixClient", function () {
803806
} else {
804807
throw new Error("Unexpected event type or state key");
805808
}
809+
/* eslint-enable jest/no-conditional-expect */
806810
},
807811
} as Room["currentState"],
808812
} as unknown as Room;
@@ -820,6 +824,7 @@ describe("MatrixClient", function () {
820824
getMyMembership: () => "join",
821825
currentState: {
822826
getStateEvents: (eventType, stateKey) => {
827+
/* eslint-disable jest/no-conditional-expect */
823828
if (eventType === EventType.RoomCreate) {
824829
expect(stateKey).toEqual("");
825830
return new MatrixEvent({
@@ -837,6 +842,7 @@ describe("MatrixClient", function () {
837842
} else {
838843
throw new Error("Unexpected event type or state key");
839844
}
845+
/* eslint-enable jest/no-conditional-expect */
840846
},
841847
} as Room["currentState"],
842848
} as unknown as Room;
@@ -858,6 +864,7 @@ describe("MatrixClient", function () {
858864
const syncPromise = new Promise<void>((resolve, reject) => {
859865
client.on(ClientEvent.Sync, function syncListener(state) {
860866
if (state === "SYNCING") {
867+
// eslint-disable-next-line jest/no-conditional-expect
861868
expect(httpLookups.length).toEqual(0);
862869
client.removeListener(ClientEvent.Sync, syncListener);
863870
resolve();
@@ -944,6 +951,7 @@ describe("MatrixClient", function () {
944951

945952
const wasPreparedPromise = new Promise((resolve) => {
946953
client.on(ClientEvent.Sync, function syncListener(state) {
954+
/* eslint-disable jest/no-conditional-expect */
947955
if (state === "ERROR" && httpLookups.length > 0) {
948956
expect(httpLookups.length).toEqual(2);
949957
expect(client.retryImmediately()).toBe(true);
@@ -955,6 +963,7 @@ describe("MatrixClient", function () {
955963
// unexpected state transition!
956964
expect(state).toEqual(null);
957965
}
966+
/* eslint-enable jest/no-conditional-expect */
958967
});
959968
});
960969
await client.startClient();
@@ -976,8 +985,10 @@ describe("MatrixClient", function () {
976985
const isSyncingPromise = new Promise((resolve) => {
977986
client.on(ClientEvent.Sync, function syncListener(state) {
978987
if (state === "ERROR" && httpLookups.length > 0) {
988+
/* eslint-disable jest/no-conditional-expect */
979989
expect(httpLookups.length).toEqual(1);
980990
expect(client.retryImmediately()).toBe(true);
991+
/* eslint-enable jest/no-conditional-expect */
981992
jest.advanceTimersByTime(1);
982993
} else if (state === "RECONNECTING" && httpLookups.length > 0) {
983994
jest.advanceTimersByTime(10000);
@@ -1004,6 +1015,7 @@ describe("MatrixClient", function () {
10041015

10051016
const wasPreparedPromise = new Promise((resolve) => {
10061017
client.on(ClientEvent.Sync, function syncListener(state) {
1018+
/* eslint-disable jest/no-conditional-expect */
10071019
if (state === "ERROR" && httpLookups.length > 0) {
10081020
expect(httpLookups.length).toEqual(3);
10091021
expect(client.retryImmediately()).toBe(true);
@@ -1015,6 +1027,7 @@ describe("MatrixClient", function () {
10151027
// unexpected state transition!
10161028
expect(state).toEqual(null);
10171029
}
1030+
/* eslint-enable jest/no-conditional-expect */
10181031
});
10191032
});
10201033
await client.startClient();

spec/unit/models/MSC3089Branch.spec.ts

+2
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,13 @@ describe("MSC3089Branch", () => {
265265
expect(eventType).toEqual(UNSTABLE_MSC3089_BRANCH.unstable); // test that we're definitely using the unstable value
266266
expect(stateKey).toEqual(stateKeyOrder[stateFn.mock.calls.length - 1]);
267267
if (stateKey === fileEventId) {
268+
// eslint-disable-next-line jest/no-conditional-expect
268269
expect(content).toMatchObject({
269270
retained: true, // canary for copying state
270271
active: false,
271272
});
272273
} else if (stateKey === fileEventId2) {
274+
// eslint-disable-next-line jest/no-conditional-expect
273275
expect(content).toMatchObject({
274276
active: true,
275277
version: 2,

spec/unit/models/MSC3089TreeSpace.spec.ts

+12-20
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,8 @@ describe("MSC3089TreeSpace", () => {
130130
return Promise.reject(new MatrixError({ errcode: "M_FORBIDDEN", error: "Sample Failure" }));
131131
});
132132
client.invite = fn;
133-
try {
134-
await tree.invite(target, false, false);
135133

136-
// noinspection ExceptionCaughtLocallyJS
137-
throw new Error("Failed to fail");
138-
} catch (e) {
139-
expect((<MatrixError>e).errcode).toEqual("M_FORBIDDEN");
140-
}
134+
await expect(tree.invite(target, false, false)).rejects.toThrow("MatrixError: Sample Failure");
141135

142136
expect(fn).toHaveBeenCalledTimes(1);
143137
});
@@ -357,13 +351,18 @@ describe("MSC3089TreeSpace", () => {
357351
.fn()
358352
.mockImplementation(async (roomId: string, eventType: EventType, content: any, stateKey: string) => {
359353
expect([tree.roomId, subspaceId]).toContain(roomId);
354+
355+
let expectedType: string;
356+
let expectedStateKey: string;
360357
if (roomId === subspaceId) {
361-
expect(eventType).toEqual(EventType.SpaceParent);
362-
expect(stateKey).toEqual(tree.roomId);
358+
expectedType = EventType.SpaceParent;
359+
expectedStateKey = tree.roomId;
363360
} else {
364-
expect(eventType).toEqual(EventType.SpaceChild);
365-
expect(stateKey).toEqual(subspaceId);
361+
expectedType = EventType.SpaceChild;
362+
expectedStateKey = subspaceId;
366363
}
364+
expect(eventType).toEqual(expectedType);
365+
expect(stateKey).toEqual(expectedStateKey);
367366
expect(content).toMatchObject({ via: [domain] });
368367

369368
// return value not used
@@ -629,15 +628,8 @@ describe("MSC3089TreeSpace", () => {
629628
});
630629

631630
it("should throw when setting an order at the top level space", async () => {
632-
try {
633-
// The tree is what we've defined as top level, so it should work
634-
await tree.setOrder(2);
635-
636-
// noinspection ExceptionCaughtLocallyJS
637-
throw new Error("Failed to fail");
638-
} catch (e) {
639-
expect((<Error>e).message).toEqual("Cannot set order of top level spaces currently");
640-
}
631+
// The tree is what we've defined as top level, so it should work
632+
await expect(tree.setOrder(2)).rejects.toThrow("Cannot set order of top level spaces currently");
641633
});
642634

643635
it("should return a stable order for unordered children", () => {

0 commit comments

Comments
 (0)