Fix jest/valid-expects lints (#11238)
This commit is contained in:
parent
d7d60a3255
commit
f5f31eb7d8
7 changed files with 27 additions and 26 deletions
|
@ -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",
|
||||
},
|
||||
|
|
|
@ -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", () => {
|
||||
|
|
|
@ -79,7 +79,7 @@ describe("<CreateRoomDialog />", () => {
|
|||
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("<CreateRoomDialog />", () => {
|
|||
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("<CreateRoomDialog />", () => {
|
|||
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("<CreateRoomDialog />", () => {
|
|||
// 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("<CreateRoomDialog />", () => {
|
|||
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 () => {
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -509,18 +509,23 @@ describe("<DeviceItem />", () => {
|
|||
});
|
||||
|
||||
it("when userId is the same as userId from client, uses isCrossSigningVerified to determine if button is shown", async () => {
|
||||
const deferred = defer<DeviceVerificationStatus>();
|
||||
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 () => {
|
||||
|
|
|
@ -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.",
|
||||
);
|
||||
});
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue