You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-07-31 13:44:28 +03:00
Update tests to prefer RTL over Enzyme (#10247
* Update tests to prefer RTL over Enzyme * Strict types
This commit is contained in:
committed by
GitHub
parent
dd6fc124d7
commit
f40d15388c
@ -14,10 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// eslint-disable-next-line deprecate/import
|
||||
import { ReactWrapper } from "enzyme";
|
||||
import { act } from "react-dom/test-utils";
|
||||
import { act as actRTL, fireEvent, RenderResult } from "@testing-library/react";
|
||||
import { act, fireEvent, RenderResult } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
|
||||
export const addTextToComposer = (container: HTMLElement, text: string) =>
|
||||
@ -34,23 +31,8 @@ export const addTextToComposer = (container: HTMLElement, text: string) =>
|
||||
fireEvent.paste(container.querySelector('[role="textbox"]')!, pasteEvent);
|
||||
});
|
||||
|
||||
export const addTextToComposerEnzyme = (wrapper: ReactWrapper, text: string) =>
|
||||
act(() => {
|
||||
// couldn't get input event on contenteditable to work
|
||||
// paste works without illegal private method access
|
||||
const pasteEvent: Partial<ClipboardEvent> = {
|
||||
clipboardData: {
|
||||
types: [],
|
||||
files: [],
|
||||
getData: (type: string) => (type === "text/plain" ? text : undefined),
|
||||
} as unknown as DataTransfer,
|
||||
};
|
||||
wrapper.find('[role="textbox"]').simulate("paste", pasteEvent);
|
||||
wrapper.update();
|
||||
});
|
||||
|
||||
export const addTextToComposerRTL = async (renderResult: RenderResult, text: string): Promise<void> => {
|
||||
await actRTL(async () => {
|
||||
await act(async () => {
|
||||
await userEvent.click(renderResult.getByLabelText("Send a message…"));
|
||||
await userEvent.keyboard(text);
|
||||
});
|
||||
|
@ -96,7 +96,7 @@ export function createTestClient(): MatrixClient {
|
||||
getUserId: jest.fn().mockReturnValue("@userId:matrix.org"),
|
||||
getSafeUserId: jest.fn().mockReturnValue("@userId:matrix.org"),
|
||||
getUserIdLocalpart: jest.fn().mockResolvedValue("userId"),
|
||||
getUser: jest.fn().mockReturnValue({ on: jest.fn() }),
|
||||
getUser: jest.fn().mockReturnValue({ on: jest.fn(), off: jest.fn() }),
|
||||
getDevice: jest.fn(),
|
||||
getDeviceId: jest.fn().mockReturnValue("ABCDEFGHI"),
|
||||
getStoredCrossSigningForUser: jest.fn(),
|
||||
@ -455,6 +455,7 @@ export function mkRoomMember(roomId: string, userId: string, membership = "join"
|
||||
getAvatarUrl: () => {},
|
||||
getMxcAvatarUrl: () => {},
|
||||
getDMInviter: () => {},
|
||||
off: () => {},
|
||||
} as unknown as RoomMember;
|
||||
}
|
||||
|
||||
|
@ -14,8 +14,6 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// eslint-disable-next-line deprecate/import
|
||||
import { ReactWrapper } from "enzyme";
|
||||
import EventEmitter from "events";
|
||||
|
||||
import { ActionPayload } from "../../src/dispatcher/payloads";
|
||||
@ -128,17 +126,6 @@ export function untilEmission(
|
||||
});
|
||||
}
|
||||
|
||||
export const findByAttr = (attr: string) => (component: ReactWrapper, value: string) =>
|
||||
component.find(`[${attr}="${value}"]`);
|
||||
export const findByTestId = findByAttr("data-test-id");
|
||||
export const findById = findByAttr("id");
|
||||
export const findByAriaLabel = findByAttr("aria-label");
|
||||
|
||||
const findByTagAndAttr = (attr: string) => (component: ReactWrapper, value: string, tag: string) =>
|
||||
component.find(`${tag}[${attr}="${value}"]`);
|
||||
|
||||
export const findByTagAndTestId = findByTagAndAttr("data-test-id");
|
||||
|
||||
export const flushPromises = async () => await new Promise((resolve) => window.setTimeout(resolve));
|
||||
|
||||
// with jest's modern fake timers process.nextTick is also mocked,
|
||||
|
Reference in New Issue
Block a user