diff --git a/.eslintrc.js b/.eslintrc.js index 568a106ee6..f863b7d138 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -174,9 +174,6 @@ module.exports = { // Disabled tests are a reality for now but as soon as all of the xits are // eliminated, we should enforce this. "jest/no-disabled-tests": "off", - // TODO: There are many tests with invalid expects that should be fixed, - // https://github.com/vector-im/element-web/issues/24709 - "jest/valid-expect": "off", // Also treat "oldBackendOnly" as a test function. // Used in some crypto tests. "jest/no-standalone-expect": [ @@ -194,6 +191,7 @@ module.exports = { }, rules: { // Cypress "promises" work differently - disable some related rules + "jest/valid-expect": "off", "jest/valid-expect-in-promise": "off", "jest/no-done-callback": "off", }, diff --git a/test/components/views/dialogs/ConfirmRedactDialog-test.tsx b/test/components/views/dialogs/ConfirmRedactDialog-test.tsx index 57e386cb17..6623e5a3b6 100644 --- a/test/components/views/dialogs/ConfirmRedactDialog-test.tsx +++ b/test/components/views/dialogs/ConfirmRedactDialog-test.tsx @@ -60,9 +60,7 @@ describe("ConfirmRedactDialog", () => { user: client.getSafeUserId(), }); jest.spyOn(mxEvent, "getId").mockReturnValue(undefined); - expect(async () => { - await confirmDeleteVoiceBroadcastStartedEvent(); - }).rejects.toThrow("cannot redact event without ID"); + await expect(confirmDeleteVoiceBroadcastStartedEvent()).rejects.toThrow("cannot redact event without ID"); }); it("should raise an error for an event without room-ID", async () => { @@ -74,9 +72,9 @@ describe("ConfirmRedactDialog", () => { user: client.getSafeUserId(), }); jest.spyOn(mxEvent, "getRoomId").mockReturnValue(undefined); - expect(async () => { - await confirmDeleteVoiceBroadcastStartedEvent(); - }).rejects.toThrow(`cannot redact event ${mxEvent.getId()} without room ID`); + await expect(confirmDeleteVoiceBroadcastStartedEvent()).rejects.toThrow( + `cannot redact event ${mxEvent.getId()} without room ID`, + ); }); describe("when redacting a voice broadcast started event", () => { diff --git a/test/components/views/dialogs/CreateRoomDialog-test.tsx b/test/components/views/dialogs/CreateRoomDialog-test.tsx index b319c28865..9a43cc63de 100644 --- a/test/components/views/dialogs/CreateRoomDialog-test.tsx +++ b/test/components/views/dialogs/CreateRoomDialog-test.tsx @@ -79,7 +79,7 @@ describe("", () => { screen.getByText( "Your server admin has disabled end-to-end encryption by default in private rooms & Direct Messages.", ), - ); + ).toBeDefined(); }); it("should use server .well-known force_disable for encryption setting", async () => { @@ -99,7 +99,7 @@ describe("", () => { screen.getByText( "Your server admin has disabled end-to-end encryption by default in private rooms & Direct Messages.", ), - ); + ).toBeDefined(); }); it("should use defaultEncrypted prop", async () => { @@ -150,7 +150,7 @@ describe("", () => { screen.getByText( "Your server admin has disabled end-to-end encryption by default in private rooms & Direct Messages.", ), - ); + ).toBeDefined(); }); it("should override defaultEncrypted when server forces enabled encryption", async () => { @@ -161,7 +161,7 @@ describe("", () => { // server forces encryption to enabled, even though defaultEncrypted is true expect(getE2eeEnableToggleInputElement()).toBeChecked(); expect(getE2eeEnableToggleIsDisabled()).toBeTruthy(); - expect(screen.getByText("Your server requires encryption to be enabled in private rooms.")); + expect(screen.getByText("Your server requires encryption to be enabled in private rooms.")).toBeDefined(); }); it("should enable encryption toggle and disable field when server forces encryption", async () => { @@ -172,7 +172,7 @@ describe("", () => { expect(getE2eeEnableToggleInputElement()).toBeChecked(); expect(getE2eeEnableToggleIsDisabled()).toBeTruthy(); - expect(screen.getByText("Your server requires encryption to be enabled in private rooms.")); + expect(screen.getByText("Your server requires encryption to be enabled in private rooms.")).toBeDefined(); }); it("should warn when trying to create a room with an invalid form", async () => { diff --git a/test/components/views/dialogs/DevtoolsDialog-test.tsx b/test/components/views/dialogs/DevtoolsDialog-test.tsx index 27f1206f92..0269826f92 100644 --- a/test/components/views/dialogs/DevtoolsDialog-test.tsx +++ b/test/components/views/dialogs/DevtoolsDialog-test.tsx @@ -66,7 +66,7 @@ describe("DevtoolsDialog", () => { expect(copiedBtn).toBeInTheDocument(); expect(navigator.clipboard.writeText).toHaveBeenCalled(); - expect(navigator.clipboard.readText()).resolves.toBe(room.roomId); + await expect(navigator.clipboard.readText()).resolves.toBe(room.roomId); }); it("copies the thread root id when provided", async () => { @@ -82,6 +82,6 @@ describe("DevtoolsDialog", () => { expect(copiedBtn).toBeInTheDocument(); expect(navigator.clipboard.writeText).toHaveBeenCalled(); - expect(navigator.clipboard.readText()).resolves.toBe(threadRootId); + await expect(navigator.clipboard.readText()).resolves.toBe(threadRootId); }); }); diff --git a/test/components/views/right_panel/UserInfo-test.tsx b/test/components/views/right_panel/UserInfo-test.tsx index 2875f7691c..f158384ff2 100644 --- a/test/components/views/right_panel/UserInfo-test.tsx +++ b/test/components/views/right_panel/UserInfo-test.tsx @@ -509,18 +509,23 @@ describe("", () => { }); it("when userId is the same as userId from client, uses isCrossSigningVerified to determine if button is shown", async () => { + const deferred = defer(); + mockCrypto.getDeviceVerificationStatus.mockReturnValue(deferred.promise); + mockClient.getSafeUserId.mockReturnValueOnce(defaultUserId); mockClient.getUserId.mockReturnValueOnce(defaultUserId); renderComponent(); await act(flushPromises); // set trust to be false for isVerified, true for isCrossSigningVerified - setMockDeviceTrust(false, true); + deferred.resolve({ + isVerified: () => false, + crossSigningVerified: true, + } as DeviceVerificationStatus); + await expect(screen.findByText(device.displayName!)).resolves.toBeInTheDocument(); // expect to see no button in this case - // TODO `toBeInTheDocument` is not called, if called the test is failing - expect(screen.queryByRole("button")).not.toBeInTheDocument; - expect(screen.getByText(device.displayName!)).toBeInTheDocument(); + expect(screen.queryByRole("button")).not.toBeInTheDocument(); }); it("with verified user and device, displays no button and a 'Trusted' label", async () => { diff --git a/test/utils/oidc/authorize-test.ts b/test/utils/oidc/authorize-test.ts index 7a554562e9..75720f724f 100644 --- a/test/utils/oidc/authorize-test.ts +++ b/test/utils/oidc/authorize-test.ts @@ -114,7 +114,7 @@ describe("OIDC authorization", () => { }); it("should throw when query params do not include state and code", async () => { - expect(async () => await completeOidcLogin({})).rejects.toThrow( + await expect(completeOidcLogin({})).rejects.toThrow( "Invalid query parameters for OIDC native login. `code` and `state` are required.", ); }); diff --git a/test/utils/oidc/registerClient-test.ts b/test/utils/oidc/registerClient-test.ts index 539ec33212..4ebf754eaa 100644 --- a/test/utils/oidc/registerClient-test.ts +++ b/test/utils/oidc/registerClient-test.ts @@ -55,8 +55,8 @@ describe("getOidcClientId()", () => { issuer: "https://issuerWithoutStaticClientId.org/", registrationEndpoint: undefined, }; - expect( - async () => await getOidcClientId(authConfigWithoutRegistration, clientName, baseUrl, staticOidcClients), + await expect( + getOidcClientId(authConfigWithoutRegistration, clientName, baseUrl, staticOidcClients), ).rejects.toThrow(OidcError.DynamicRegistrationNotSupported); // didn't try to register expect(fetchMockJest).toHaveFetchedTimes(0); @@ -67,7 +67,7 @@ describe("getOidcClientId()", () => { ...delegatedAuthConfig, registrationEndpoint: undefined, }; - expect(async () => await getOidcClientId(authConfigWithoutRegistration, clientName, baseUrl)).rejects.toThrow( + await expect(getOidcClientId(authConfigWithoutRegistration, clientName, baseUrl)).rejects.toThrow( OidcError.DynamicRegistrationNotSupported, ); // didn't try to register @@ -104,7 +104,7 @@ describe("getOidcClientId()", () => { fetchMockJest.post(registrationEndpoint, { status: 500, }); - expect(() => getOidcClientId(delegatedAuthConfig, clientName, baseUrl)).rejects.toThrow( + await expect(getOidcClientId(delegatedAuthConfig, clientName, baseUrl)).rejects.toThrow( OidcError.DynamicRegistrationFailed, ); }); @@ -115,7 +115,7 @@ describe("getOidcClientId()", () => { // no clientId in response body: "{}", }); - expect(() => getOidcClientId(delegatedAuthConfig, clientName, baseUrl)).rejects.toThrow( + await expect(getOidcClientId(delegatedAuthConfig, clientName, baseUrl)).rejects.toThrow( OidcError.DynamicRegistrationInvalid, ); });