From 7b5e73207f6ecd69993f341bef3fc50e80971649 Mon Sep 17 00:00:00 2001 From: Germain Date: Tue, 22 Nov 2022 09:53:33 +0000 Subject: [PATCH] Fix SpaceTreeLevel enzyme test (#9602) --- .../views/spaces/SpaceTreeLevel-test.tsx | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/test/components/views/spaces/SpaceTreeLevel-test.tsx b/test/components/views/spaces/SpaceTreeLevel-test.tsx index eda55f6dc1..e1de2c1cdd 100644 --- a/test/components/views/spaces/SpaceTreeLevel-test.tsx +++ b/test/components/views/spaces/SpaceTreeLevel-test.tsx @@ -15,8 +15,7 @@ limitations under the License. */ import React from "react"; -// eslint-disable-next-line deprecate/import -import { mount } from "enzyme"; +import { fireEvent, getByTestId, render } from "@testing-library/react"; import { stubClient, mkRoom } from "../../../test-utils"; import { MatrixClientPeg } from "../../../../src/MatrixClientPeg"; @@ -49,35 +48,51 @@ describe("SpaceButton", () => { describe("real space", () => { it("activates the space on click", () => { - const button = mount(); + const { container } = render(); expect(SpaceStore.instance.setActiveSpace).not.toHaveBeenCalled(); - button.simulate("click"); + fireEvent.click(getByTestId(container, "create-space-button")); expect(SpaceStore.instance.setActiveSpace).toHaveBeenCalledWith("!1:example.org"); }); it("navigates to the space home on click if already active", () => { - const button = mount(); + const { container } = render(); expect(dispatchSpy).not.toHaveBeenCalled(); - button.simulate("click"); + fireEvent.click(getByTestId(container, "create-space-button")); expect(dispatchSpy).toHaveBeenCalledWith({ action: Action.ViewRoom, room_id: "!1:example.org" }); }); }); describe("metaspace", () => { it("activates the metaspace on click", () => { - const button = mount(); + const { container } = render(); expect(SpaceStore.instance.setActiveSpace).not.toHaveBeenCalled(); - button.simulate("click"); + fireEvent.click(getByTestId(container, "create-space-button")); expect(SpaceStore.instance.setActiveSpace).toHaveBeenCalledWith(MetaSpace.People); }); it("does nothing on click if already active", () => { - const button = mount(); + const { container } = render(); - button.simulate("click"); + fireEvent.click(getByTestId(container, "create-space-button")); expect(dispatchSpy).not.toHaveBeenCalled(); // Re-activating the metaspace is a no-op expect(SpaceStore.instance.setActiveSpace).toHaveBeenCalledWith(MetaSpace.People);