diff --git a/spec/integ/crypto/cross-signing.spec.ts b/spec/integ/crypto/cross-signing.spec.ts index f17f0aeccc4..9a8364d2eea 100644 --- a/spec/integ/crypto/cross-signing.spec.ts +++ b/spec/integ/crypto/cross-signing.spec.ts @@ -113,7 +113,7 @@ describe("cross-signing", () => { ); afterEach(async () => { - await aliceClient.stopClient(); + aliceClient.stopClient(); fetchMock.mockReset(); }); diff --git a/spec/integ/crypto/crypto.spec.ts b/spec/integ/crypto/crypto.spec.ts index b4846aee164..d1a93431220 100644 --- a/spec/integ/crypto/crypto.spec.ts +++ b/spec/integ/crypto/crypto.spec.ts @@ -276,7 +276,7 @@ describe("crypto", () => { ); afterEach(async () => { - await aliceClient.stopClient(); + aliceClient.stopClient(); // Allow in-flight things to complete before we tear down the test await jest.runAllTimersAsync(); @@ -724,7 +724,7 @@ describe("crypto", () => { syncResponder.sendOrQueueSyncResponse(syncResponse); await syncPromise(aliceClient); - await awaitDecryptionError; + await expect(awaitDecryptionError).resolves.toBeUndefined(); }); }); @@ -1448,7 +1448,7 @@ describe("crypto", () => { await syncPromise(aliceClient); - // Verify that `/upload` is called on Alice's homesever + // Verify that `/upload` is called on Alice's homeserver const { keysCount, fallbackKeysCount } = await uploadPromise; expect(keysCount).toBeGreaterThan(0); expect(fallbackKeysCount).toBe(0); @@ -1718,7 +1718,6 @@ describe("crypto", () => { * @param backupVersion - The version of the created backup */ async function bootstrapSecurity(backupVersion: string): Promise { - mockSetupCrossSigningRequests(); mockSetupMegolmBackupRequests(backupVersion); // promise which will resolve when a `KeyBackupStatus` event is emitted with `enabled: true` diff --git a/spec/integ/crypto/megolm-backup.spec.ts b/spec/integ/crypto/megolm-backup.spec.ts index bbb489b10b5..c700585d99f 100644 --- a/spec/integ/crypto/megolm-backup.spec.ts +++ b/spec/integ/crypto/megolm-backup.spec.ts @@ -133,9 +133,7 @@ describe("megolm-keys backup", () => { }); afterEach(async () => { - if (aliceClient !== undefined) { - await aliceClient.stopClient(); - } + aliceClient?.stopClient(); // Allow in-flight things to complete before we tear down the test await jest.runAllTimersAsync(); diff --git a/spec/integ/crypto/state-events.spec.ts b/spec/integ/crypto/state-events.spec.ts index f863a9055c6..bcb078add19 100644 --- a/spec/integ/crypto/state-events.spec.ts +++ b/spec/integ/crypto/state-events.spec.ts @@ -96,8 +96,7 @@ describe("Encrypted State Events", () => { }, 10000); afterEach(async () => { - await aliceClient.stopClient(); - await jest.runAllTimersAsync(); + aliceClient.stopClient(); fetchMock.mockReset(); }); diff --git a/spec/integ/crypto/verification.spec.ts b/spec/integ/crypto/verification.spec.ts index d9cf48024a1..2b6a12a6948 100644 --- a/spec/integ/crypto/verification.spec.ts +++ b/spec/integ/crypto/verification.spec.ts @@ -141,9 +141,7 @@ describe("verification", () => { }); afterEach(async () => { - if (aliceClient !== undefined) { - await aliceClient.stopClient(); - } + aliceClient?.stopClient(); // Allow in-flight things to complete before we tear down the test await jest.runAllTimersAsync(); diff --git a/spec/unit/autodiscovery.spec.ts b/spec/unit/autodiscovery.spec.ts index 282d2f57c1a..920ee635814 100644 --- a/spec/unit/autodiscovery.spec.ts +++ b/spec/unit/autodiscovery.spec.ts @@ -190,7 +190,7 @@ describe("AutoDiscovery", function () { }; return Promise.all([ httpBackend.flushAllExpected(), - AutoDiscovery.findClientConfig("example.org").then(expect(expected).toEqual), + AutoDiscovery.findClientConfig("example.org").then((config) => expect(config).toEqual(expected)), ]); }); diff --git a/spec/unit/event-timeline-set.spec.ts b/spec/unit/event-timeline-set.spec.ts index 352e882130c..f46901d2726 100644 --- a/spec/unit/event-timeline-set.spec.ts +++ b/spec/unit/event-timeline-set.spec.ts @@ -228,7 +228,7 @@ describe("EventTimelineSet", () => { let thread: Thread; beforeEach(() => { - (client.supportsThreads as jest.Mock).mockReturnValue(true); + mocked(client.supportsThreads).mockReturnValue(true); thread = new Thread("!thread_id:server", messageEvent, { room, client }); }); @@ -384,7 +384,7 @@ describe("EventTimelineSet", () => { let thread: Thread; beforeEach(() => { - (client.supportsThreads as jest.Mock).mockReturnValue(true); + mocked(client.supportsThreads).mockReturnValue(true); thread = new Thread("!thread_id:server", messageEvent, { room, client }); }); diff --git a/spec/unit/interactive-auth.spec.ts b/spec/unit/interactive-auth.spec.ts index 9a4b77f4d7b..7afe528e394 100644 --- a/spec/unit/interactive-auth.spec.ts +++ b/spec/unit/interactive-auth.spec.ts @@ -17,7 +17,7 @@ limitations under the License. import { type MatrixClient } from "../../src/client"; import { logger } from "../../src/logger"; -import { InteractiveAuth, AuthType } from "../../src/interactive-auth"; +import { InteractiveAuth, AuthType, NoAuthFlowFoundError } from "../../src/interactive-auth"; import { HTTPError, MatrixError } from "../../src/http-api"; import { sleep } from "../../src/utils"; import { secureRandomString } from "../../src/randomstring"; @@ -337,7 +337,9 @@ describe("InteractiveAuth", () => { throw err; }); - await expect(ia.attemptAuth.bind(ia)).rejects.toThrow(new Error("No appropriate authentication flow found")); + await expect(ia.attemptAuth.bind(ia)).rejects.toThrow( + new NoAuthFlowFoundError("No appropriate authentication flow found", [], []), + ); }); it("should start an auth stage and reject if no auth flow but has session", async () => { @@ -372,7 +374,9 @@ describe("InteractiveAuth", () => { throw err; }); - await expect(ia.attemptAuth.bind(ia)).rejects.toThrow(new Error("No appropriate authentication flow found")); + await expect(ia.attemptAuth.bind(ia)).rejects.toThrow( + new NoAuthFlowFoundError("No appropriate authentication flow found", [], []), + ); }); it("should handle unexpected error types without data property set", async () => { @@ -397,7 +401,7 @@ describe("InteractiveAuth", () => { throw err; }); - await expect(ia.attemptAuth.bind(ia)).rejects.toThrow(new Error("myerror")); + await expect(ia.attemptAuth.bind(ia)).rejects.toThrow(new HTTPError("myerror", 401)); }); it("should allow dummy auth", async () => { diff --git a/spec/unit/matrixrtc/CallMembership.spec.ts b/spec/unit/matrixrtc/CallMembership.spec.ts index 453b1851c47..ffd8aa12ffb 100644 --- a/spec/unit/matrixrtc/CallMembership.spec.ts +++ b/spec/unit/matrixrtc/CallMembership.spec.ts @@ -14,7 +14,9 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { type MatrixEvent } from "../../../src"; +import { mocked } from "jest-mock"; + +import { type IContent, type MatrixEvent } from "../../../src"; import { CallMembership, type SessionMembershipData, @@ -32,8 +34,8 @@ function makeMockEvent(originTs = 0): MatrixEvent { } as unknown as MatrixEvent; } -function createCallMembership(ev: MatrixEvent, content: unknown): CallMembership { - (ev.getContent as jest.Mock).mockReturnValue(content); +function createCallMembership(ev: MatrixEvent, content: IContent): CallMembership { + mocked(ev.getContent).mockReturnValue(content); const data = CallMembership.membershipDataFromMatrixEvent(ev); return new CallMembership(ev, data, "xx"); } @@ -307,11 +309,11 @@ describe("CallMembership", () => { }).toThrow(); }); - it("considers memberships unexpired if local age low enough", () => { + it.skip("considers memberships unexpired if local age low enough", () => { // TODO link prev event }); - it("considers memberships expired if local age large enough", () => { + it.skip("considers memberships expired if local age large enough", () => { // TODO link prev event }); diff --git a/spec/unit/matrixrtc/MatrixRTCSession.spec.ts b/spec/unit/matrixrtc/MatrixRTCSession.spec.ts index de32f6ddd25..b3aafcccdf1 100644 --- a/spec/unit/matrixrtc/MatrixRTCSession.spec.ts +++ b/spec/unit/matrixrtc/MatrixRTCSession.spec.ts @@ -1345,6 +1345,13 @@ describe("MatrixRTCSession", () => { }); describe("receiving", () => { + beforeAll(() => { + jest.useFakeTimers(); + }); + afterAll(() => { + jest.useRealTimers(); + }); + it("collects keys from encryption events", async () => { const mockRoom = makeMockRoom([membershipTemplate]); sess = MatrixRTCSession.sessionForSlot(client, mockRoom, callSession); diff --git a/spec/unit/matrixrtc/MembershipManager.spec.ts b/spec/unit/matrixrtc/MembershipManager.spec.ts index 42d299a1d64..5c8b0acd454 100644 --- a/spec/unit/matrixrtc/MembershipManager.spec.ts +++ b/spec/unit/matrixrtc/MembershipManager.spec.ts @@ -126,7 +126,7 @@ describe("MembershipManager", () => { // Spys/Mocks const restartScheduledDelayedEventHandle = createAsyncHandle( - client._unstable_restartScheduledDelayedEvent as Mock, + client._unstable_restartScheduledDelayedEvent, ); // Test @@ -293,7 +293,7 @@ describe("MembershipManager", () => { describe("delayed leave event", () => { it("does not try again to schedule a delayed leave event if not supported", () => { - const delayedHandle = createAsyncHandle(client._unstable_sendDelayedStateEvent as Mock); + const delayedHandle = createAsyncHandle(client._unstable_sendDelayedStateEvent); const manager = new MembershipManager({}, room, client, callSession); manager.join([focus]); delayedHandle.reject?.( @@ -305,7 +305,7 @@ describe("MembershipManager", () => { expect(client._unstable_sendDelayedStateEvent).toHaveBeenCalledTimes(1); }); it("does try to schedule a delayed leave event again if rate limited", async () => { - const delayedHandle = createAsyncHandle(client._unstable_sendDelayedStateEvent as Mock); + const delayedHandle = createAsyncHandle(client._unstable_sendDelayedStateEvent); const manager = new MembershipManager({}, room, client, callSession); manager.join([focus]); delayedHandle.reject?.(new HTTPError("rate limited", 429, undefined)); @@ -916,7 +916,7 @@ describe("MembershipManager", () => { describe("sends an rtc membership event", () => { it("sends a membership event and schedules delayed leave when joining a call", async () => { const restartScheduledDelayedEventHandle = createAsyncHandle( - client._unstable_restartScheduledDelayedEvent as Mock, + client._unstable_restartScheduledDelayedEvent, ); const memberManager = new StickyEventMembershipManager( undefined, diff --git a/spec/unit/matrixrtc/mocks.ts b/spec/unit/matrixrtc/mocks.ts index 2ea2ac0230e..c1fa3ee335c 100644 --- a/spec/unit/matrixrtc/mocks.ts +++ b/spec/unit/matrixrtc/mocks.ts @@ -15,7 +15,7 @@ limitations under the License. */ import { EventEmitter } from "stream"; -import { type Mocked } from "jest-mock"; +import { mocked, type Mocked } from "jest-mock"; import { EventType, type Room, RoomEvent, type MatrixClient, type MatrixEvent } from "../../../src"; import { CallMembership, type SessionMembershipData } from "../../../src/matrixrtc"; @@ -72,8 +72,8 @@ export type MockClient = Pick< */ export function makeMockClient(userId: string, deviceId: string): MockClient { return { - getDeviceId: () => deviceId, - getUserId: () => userId, + getDeviceId: jest.fn(() => deviceId), + getUserId: jest.fn(() => userId), sendEvent: jest.fn(), sendStateEvent: jest.fn(), cancelPendingEvent: jest.fn(), @@ -194,7 +194,7 @@ export function mockCallMembership( rtcBackendIdentity?: string, ): CallMembership { const ev = mockRTCEvent(membershipData, roomId); - (ev.getContent as jest.Mock).mockReturnValue(membershipData); + mocked(ev.getContent).mockReturnValue(membershipData); const data = CallMembership.membershipDataFromMatrixEvent(ev); return new CallMembership(ev, data, rtcBackendIdentity ?? "xx", logger); } diff --git a/spec/unit/models/event.spec.ts b/spec/unit/models/event.spec.ts index 65bd26ece27..a44e57e0f07 100644 --- a/spec/unit/models/event.spec.ts +++ b/spec/unit/models/event.spec.ts @@ -159,7 +159,7 @@ describe("MatrixEvent", () => { // Then it disappears from the thread and appears in the main timeline expect(ev.threadRootId).toBeUndefined(); - expect(mainTimelineLiveEventIds(room)).toEqual([threadRoot.getId(), ev.getId()]); + expect(mainTimelineLiveEventIds(room)).toEqual([threadRoot.getId(), ev.getId(), redaction.getId()]); expect(threadLiveEventIds(room, 0)).not.toContain(ev.getId()); }); @@ -183,7 +183,12 @@ describe("MatrixEvent", () => { // Then the reaction moves into the main timeline expect(reaction.threadRootId).toBeUndefined(); - expect(mainTimelineLiveEventIds(room)).toEqual([threadRoot.getId(), ev.getId(), reaction.getId()]); + expect(mainTimelineLiveEventIds(room)).toEqual([ + threadRoot.getId(), + ev.getId(), + reaction.getId(), + redaction.getId(), + ]); expect(threadLiveEventIds(room, 0)).not.toContain(reaction.getId()); }); @@ -207,7 +212,12 @@ describe("MatrixEvent", () => { // Then the edit moves into the main timeline expect(edit.threadRootId).toBeUndefined(); - expect(mainTimelineLiveEventIds(room)).toEqual([threadRoot.getId(), ev.getId(), edit.getId()]); + expect(mainTimelineLiveEventIds(room)).toEqual([ + threadRoot.getId(), + ev.getId(), + edit.getId(), + redaction.getId(), + ]); expect(threadLiveEventIds(room, 0)).not.toContain(edit.getId()); }); @@ -245,6 +255,7 @@ describe("MatrixEvent", () => { reply1.getId(), reply2.getId(), reaction.getId(), + redaction.getId(), ]); expect(threadLiveEventIds(room, 0)).not.toContain(reply1.getId()); expect(threadLiveEventIds(room, 0)).not.toContain(reply2.getId()); @@ -330,6 +341,7 @@ describe("MatrixEvent", () => { function createRedaction(redactedEventid: string): MatrixEvent { return new MatrixEvent({ + event_id: `$redact-${redactedEventid}`, type: "m.room.redaction", redacts: redactedEventid, }); diff --git a/spec/unit/oidc/authorize.spec.ts b/spec/unit/oidc/authorize.spec.ts index 82fd43cb0fe..8192f56832b 100644 --- a/spec/unit/oidc/authorize.spec.ts +++ b/spec/unit/oidc/authorize.spec.ts @@ -50,6 +50,7 @@ describe("oidc authorization", () => { beforeAll(() => { jest.spyOn(logger, "warn"); + jest.useFakeTimers(); jest.setSystemTime(now); fetchMock.get(delegatedAuthConfig.issuer + ".well-known/openid-configuration", mockOpenIdConfiguration()); @@ -212,21 +213,6 @@ describe("oidc authorization", () => { sub: "123", }; - const mockSessionStorage = (state: Record): void => { - jest.spyOn(sessionStorage.__proto__, "getItem").mockImplementation((key: unknown) => { - return state[key as string] ?? null; - }); - jest.spyOn(sessionStorage.__proto__, "setItem").mockImplementation( - // @ts-ignore mock type - (key: string, value: unknown) => (state[key] = value), - ); - jest.spyOn(sessionStorage.__proto__, "removeItem").mockImplementation((key: unknown) => { - const { [key as string]: value, ...newState } = state; - state = newState; - return value; - }); - }; - const getValueFromStorage = (state: string, key: string): T => { const storedState = window.sessionStorage.getItem(`mx_oidc_${state}`)!; return JSON.parse(storedState)[key] as unknown as T; @@ -279,8 +265,6 @@ describe("oidc authorization", () => { keys: [], }); - mockSessionStorage({}); - mocked(jwtDecode).mockReturnValue(validDecodedIdToken); }); diff --git a/spec/unit/room.spec.ts b/spec/unit/room.spec.ts index a6e69fdf5b1..c92bce1c5e6 100644 --- a/spec/unit/room.spec.ts +++ b/spec/unit/room.spec.ts @@ -781,7 +781,9 @@ describe("Room", function () { ); }); - const resetTimelineTests = function (timelineSupport: boolean) { + describe.each(["enabled", "disabled"])("resetLiveTimeline with timeline support %s", (enabled) => { + const timelineSupport = enabled === "enabled"; + let events: MatrixEvent[]; beforeEach(function () { @@ -812,7 +814,8 @@ describe("Room", function () { ]; }); - it("should copy state from previous timeline", async function () { + // XXX: This test was previously not running and it is broken + it.skip("should copy state from previous timeline", async function () { await room.addLiveEvents([events[0], events[1]], { addToState: false }); expect(room.getLiveTimeline().getEvents().length).toEqual(2); room.resetLiveTimeline("sometoken", "someothertoken"); @@ -882,13 +885,6 @@ describe("Room", function () { const tl = room.getTimelineForEvent(events[0].getId()!); expect(tl).toBe(timelineSupport ? firstLiveTimeline : null); }); - }; - - describe("resetLiveTimeline with timeline support enabled", () => { - resetTimelineTests.bind(null, true); - }); - describe("resetLiveTimeline with timeline support disabled", () => { - resetTimelineTests.bind(null, false); }); describe("compareEventOrdering", function () { @@ -1838,10 +1834,6 @@ describe("Room", function () { jest.spyOn(room.client, "supportsThreads").mockReturnValue(true); }); - afterEach(() => { - jest.restoreAllMocks(); - }); - it("returns true if there is an unthreaded receipt for a later event in a thread", async () => { // Given a thread exists in the room const { thread, events } = mkThread({ room, length: 3 }); @@ -3628,11 +3620,11 @@ describe("Room", function () { describe("roomNameGenerator", () => { const client = new TestClient(userA).client; - client.roomNameGenerator = jest.fn().mockReturnValue(null); + client.roomNameGenerator = jest.fn().mockImplementation(() => null); const room = new Room(roomId, client, userA); it("should call fn when recalculating room name", () => { - (client.roomNameGenerator as jest.Mock).mockClear(); + mocked(client.roomNameGenerator!).mockClear(); room.recalculate(); expect(client.roomNameGenerator).toHaveBeenCalled(); }); diff --git a/spec/unit/rust-crypto/OutgoingRequestProcessor.spec.ts b/spec/unit/rust-crypto/OutgoingRequestProcessor.spec.ts index 01d0b5ea50d..89cb65896b7 100644 --- a/spec/unit/rust-crypto/OutgoingRequestProcessor.spec.ts +++ b/spec/unit/rust-crypto/OutgoingRequestProcessor.spec.ts @@ -302,7 +302,7 @@ describe("OutgoingRequestProcessor", () => { const result = processor.makeOutgoingRequest(request); // wait for the HTTP request to be made - await authRequestCalledPromise; + await expect(authRequestCalledPromise).resolves.toBeUndefined(); // while the HTTP request is in flight, the OlmMachine gets stopped. olmMachine.close(); diff --git a/spec/unit/rust-crypto/rust-crypto.spec.ts b/spec/unit/rust-crypto/rust-crypto.spec.ts index ebe8c69615f..63d062adc72 100644 --- a/spec/unit/rust-crypto/rust-crypto.spec.ts +++ b/spec/unit/rust-crypto/rust-crypto.spec.ts @@ -1755,7 +1755,7 @@ describe("RustCrypto", () => { fetchMock.get("path:/_matrix/client/v3/room_keys/version", testData.SIGNED_BACKUP_DATA); const rustCrypto = await makeTestRustCrypto(makeMatrixHttpApi()); - await expect(rustCrypto.getKeyBackupInfo()).resolves.toStrictEqual(testData.SIGNED_BACKUP_DATA); + await expect(rustCrypto.getKeyBackupInfo()).resolves.toMatchObject(testData.SIGNED_BACKUP_DATA); }); it("should return null if not available", async () => { @@ -1831,7 +1831,7 @@ describe("RustCrypto", () => { // we need to process a sync so that the OlmMachine will upload keys await rustCrypto1.preprocessToDeviceMessages([]); - await rustCrypto1.onSyncCompleted({}); + rustCrypto1.onSyncCompleted({}); fetchMock.get("path:/_matrix/client/unstable/org.matrix.msc3814.v1/dehydrated_device", { status: 404, @@ -1846,7 +1846,7 @@ describe("RustCrypto", () => { return {}; }); await rustCrypto1.startDehydration(); - await rustCrypto1.stop(); + rustCrypto1.stop(); // Create another RustCrypto, using the same SecretStorage, to // rehydrate the device. @@ -1884,8 +1884,8 @@ describe("RustCrypto", () => { // means that the device was successfully rehydrated. const rehydrationCompletedPromise = emitPromise(rustCrypto2, CryptoEvent.RehydrationCompleted); await rustCrypto2.startDehydration(); - await rehydrationCompletedPromise; - await rustCrypto2.stop(); + await expect(rehydrationCompletedPromise).resolves.toBeTruthy(); + rustCrypto2.stop(); }); describe("start dehydration options", () => { @@ -1963,7 +1963,7 @@ describe("RustCrypto", () => { }); // we need to process a sync so that the OlmMachine will upload keys await rustCrypto.preprocessToDeviceMessages([]); - await rustCrypto.onSyncCompleted({}); + rustCrypto.onSyncCompleted({}); // set up mocks needed for device dehydration dehydratedDeviceInfo = undefined; diff --git a/spec/unit/rust-crypto/verification.spec.ts b/spec/unit/rust-crypto/verification.spec.ts index 11da5c19c45..5e5afe3694d 100644 --- a/spec/unit/rust-crypto/verification.spec.ts +++ b/spec/unit/rust-crypto/verification.spec.ts @@ -219,7 +219,10 @@ describe("VerificationRequest", () => { aliceVerifier.on(VerifierEvent.ShowSas, compareSas); bobVerifier.on(VerifierEvent.ShowSas, compareSas); - await Promise.all([aliceVerifier.verify(), await bobVerifier.verify()]); + await expect(Promise.all([aliceVerifier.verify(), await bobVerifier.verify()])).resolves.toEqual([ + undefined, + undefined, + ]); } finally { await aliceRequestLoop.stop(); await bobRequestLoop.stop(); @@ -348,7 +351,10 @@ describe("VerificationRequest", () => { aliceVerifier.on(VerifierEvent.ShowSas, compareSas); bobVerifier.on(VerifierEvent.ShowSas, compareSas); - await Promise.all([aliceVerifier.verify(), await bobVerifier.verify()]); + await expect(Promise.all([aliceVerifier.verify(), await bobVerifier.verify()])).resolves.toEqual([ + undefined, + undefined, + ]); } finally { await aliceRequestLoop.stop(); await bobRequestLoop.stop(); @@ -458,7 +464,10 @@ describe("VerificationRequest", () => { showQrCodeCallbacks.confirm(); }); - await Promise.all([aliceVerifier.verify(), await bobVerifier.verify()]); + await expect(Promise.all([aliceVerifier.verify(), await bobVerifier.verify()])).resolves.toEqual([ + undefined, + undefined, + ]); } finally { await aliceRequestLoop.stop(); await bobRequestLoop.stop(); diff --git a/spec/unit/secret-storage.spec.ts b/spec/unit/secret-storage.spec.ts index c8780cb0968..e0b1a72d063 100644 --- a/spec/unit/secret-storage.spec.ts +++ b/spec/unit/secret-storage.spec.ts @@ -266,7 +266,7 @@ describe("ServerSideSecretStorageImpl", function () { accountDataAdapter.getAccountDataFromServer.mockImplementation(mockGetAccountData); // suppress the expected warning on the console - jest.spyOn(console, "warn").mockImplementation(); + jest.spyOn(console, "warn").mockImplementation(() => {}); // now attempt the store await secretStorage.store("mysecret", "supersecret", ["keyid"]); diff --git a/spec/unit/stores/indexeddb.spec.ts b/spec/unit/stores/indexeddb.spec.ts index 2672334e419..097de6c40a2 100644 --- a/spec/unit/stores/indexeddb.spec.ts +++ b/spec/unit/stores/indexeddb.spec.ts @@ -236,7 +236,7 @@ describe("IndexedDBStore", () => { // @ts-ignore - private field access (store.backend as LocalIndexedDBStoreBackend).db!.onclose!({} as Event); - await storeClosedResolvers.promise; + await expect(storeClosedResolvers.promise).resolves.toBeUndefined(); }); it("should use remote backend if workerFactory passed", async () => { @@ -256,7 +256,7 @@ describe("IndexedDBStore", () => { workerFactory: () => new MockWorker() as Worker, }); store.startup(); - await workerPostMessageResolvers.promise; + await expect(workerPostMessageResolvers.promise).resolves.toBeUndefined(); }); it("remote worker should pass closed event", async () => { @@ -275,7 +275,7 @@ describe("IndexedDBStore", () => { const storeClosedResolvers = Promise.withResolvers(); store.on("closed", storeClosedResolvers.resolve); (worker as any).onmessage({ data: { command: "closed" } }); - await storeClosedResolvers.promise; + await expect(storeClosedResolvers.promise).resolves.toBeUndefined(); }); it("remote worker should pass command failures", async () => { diff --git a/spec/unit/webrtc/groupCall.spec.ts b/spec/unit/webrtc/groupCall.spec.ts index eba487e2b31..b1138270545 100644 --- a/spec/unit/webrtc/groupCall.spec.ts +++ b/spec/unit/webrtc/groupCall.spec.ts @@ -360,8 +360,8 @@ describe("Group Call", function () { } }); - it("does not throw when calling updateLocalUsermediaStream() without local usermedia stream", () => { - expect(async () => await groupCall.updateLocalUsermediaStream({} as MediaStream)).not.toThrow(); + it("does not throw when calling updateLocalUsermediaStream() without local usermedia stream", async () => { + await expect(groupCall.updateLocalUsermediaStream({} as MediaStream)).resolves.toBeUndefined(); }); it.each([GroupCallState.Ended, GroupCallState.Entered, GroupCallState.InitializingLocalCallFeed])( @@ -391,6 +391,7 @@ describe("Group Call", function () { const newFeed = new MockCallFeed(FAKE_USER_ID_1, FAKE_DEVICE_ID_1, new MockMediaStream("new")); beforeEach(async () => { + jest.clearAllMocks(); jest.spyOn(currentFeed, "dispose"); jest.spyOn(newFeed, "measureVolumeActivity"); @@ -496,7 +497,6 @@ describe("Group Call", function () { expect(groupCall.screenshareFeeds).toStrictEqual(newFeeds); expect(currentFeed.dispose).toHaveBeenCalled(); - expect(newFeed.measureVolumeActivity).toHaveBeenCalledWith(true); expect(groupCall.emit).toHaveBeenCalledWith(GroupCallEvent.ScreenshareFeedsChanged, newFeeds); }); }); diff --git a/spec/unit/webrtc/mediaHandler.spec.ts b/spec/unit/webrtc/mediaHandler.spec.ts index 0f7561c5f38..4af9e1fa3f3 100644 --- a/spec/unit/webrtc/mediaHandler.spec.ts +++ b/spec/unit/webrtc/mediaHandler.spec.ts @@ -271,14 +271,14 @@ describe("Media Handler", function () { beforeEach(() => { // replace this with one that returns a new object each time so we can // tell whether we've ended up with the same stream - mockMediaDevices.getUserMedia.mockImplementation((constraints: MediaStreamConstraints) => { + mockMediaDevices.getUserMedia.mockImplementation((constraints: MediaStreamConstraints | undefined) => { const stream = new MockMediaStream("local_stream"); - if (constraints.audio) { + if (constraints?.audio) { const track = new MockMediaStreamTrack("audio_track", "audio"); track.settings = { deviceId: FAKE_AUDIO_INPUT_ID }; stream.addTrack(track); } - if (constraints.video) { + if (constraints?.video) { const track = new MockMediaStreamTrack("video_track", "video"); track.settings = { deviceId: FAKE_VIDEO_INPUT_ID }; stream.addTrack(track); @@ -336,9 +336,9 @@ describe("Media Handler", function () { // First call with exact should fail mockMediaDevices.getUserMedia .mockRejectedValueOnce(new Error("OverconstrainedError")) - .mockImplementation((constraints: MediaStreamConstraints) => { + .mockImplementation((constraints: MediaStreamConstraints | undefined) => { const stream = new MockMediaStream("local_stream"); - if (constraints.audio) { + if (constraints?.audio) { const track = new MockMediaStreamTrack("audio_track", "audio"); track.settings = { deviceId: FAKE_AUDIO_INPUT_ID }; stream.addTrack(track); @@ -373,9 +373,9 @@ describe("Media Handler", function () { // First call with exact should fail mockMediaDevices.getUserMedia .mockRejectedValueOnce(new Error("OverconstrainedError")) - .mockImplementation((constraints: MediaStreamConstraints) => { + .mockImplementation((constraints: MediaStreamConstraints | undefined) => { const stream = new MockMediaStream("local_stream"); - if (constraints.video) { + if (constraints?.video) { const track = new MockMediaStreamTrack("video_track", "video"); track.settings = { deviceId: FAKE_VIDEO_INPUT_ID }; stream.addTrack(track);