fix more type issues in unit tests (#8053)

* fix ts issues in test/components/structures

Signed-off-by: Kerry Archibald <kerrya@element.io>

* fix ts issues in test/components/views/context_menus

Signed-off-by: Kerry Archibald <kerrya@element.io>
This commit is contained in:
Kerry 2022-03-15 10:30:48 +01:00 committed by GitHub
parent 813a60a7f3
commit bc8fdac491
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 25 deletions

View file

@ -17,7 +17,8 @@ limitations under the License.
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import ReactTestUtils from 'react-dom/test-utils';
import { createClient } from "matrix-js-sdk/src/matrix";
import { mocked } from 'jest-mock';
import { createClient, MatrixClient } from "matrix-js-sdk/src/matrix";
import sdk from '../../../skinned-sdk';
import SdkConfig from '../../../../src/SdkConfig';
@ -35,10 +36,10 @@ const Login = sdk.getComponent(
describe('Login', function() {
let parentDiv;
const mockClient = {
const mockClient = mocked({
login: jest.fn().mockResolvedValue({}),
loginFlows: jest.fn(),
};
} as unknown as MatrixClient);
beforeEach(function() {
jest.spyOn(SdkConfig, "get").mockReturnValue({
@ -47,7 +48,7 @@ describe('Login', function() {
});
mockClient.login.mockClear().mockResolvedValue({});
mockClient.loginFlows.mockClear().mockResolvedValue({ flows: [{ type: "m.login.password" }] });
createClient.mockReturnValue(mockClient);
mocked(createClient).mockReturnValue(mockClient);
parentDiv = document.createElement('div');
document.body.appendChild(parentDiv);
@ -101,7 +102,7 @@ describe('Login', function() {
});
it("should show SSO button if that flow is available", async () => {
mockClient.loginFlows.mockReturnValue({ flows: [{ type: "m.login.sso" }] });
mockClient.loginFlows.mockResolvedValue({ flows: [{ type: "m.login.sso" }] });
const root = render();
await flushPromises();
@ -111,7 +112,7 @@ describe('Login', function() {
});
it("should show both SSO button and username+password if both are available", async () => {
mockClient.loginFlows.mockReturnValue({ flows: [{ type: "m.login.password" }, { type: "m.login.sso" }] });
mockClient.loginFlows.mockResolvedValue({ flows: [{ type: "m.login.password" }, { type: "m.login.sso" }] });
const root = render();
await flushPromises();
@ -124,7 +125,7 @@ describe('Login', function() {
});
it("should show multiple SSO buttons if multiple identity_providers are available", async () => {
mockClient.loginFlows.mockReturnValue({
mockClient.loginFlows.mockResolvedValue({
flows: [{
"type": "m.login.sso",
"identity_providers": [{