From ad7b77503aee07637226768b0d4f573551b96d48 Mon Sep 17 00:00:00 2001 From: Jon Koops Date: Wed, 7 Jul 2021 12:09:47 +0200 Subject: [PATCH] Convert ConfirmDialog test to use React Testing Library --- .../{__tests__ => }/ConfirmDialog.test.tsx | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) rename src/components/confirm-dialog/{__tests__ => }/ConfirmDialog.test.tsx (52%) diff --git a/src/components/confirm-dialog/__tests__/ConfirmDialog.test.tsx b/src/components/confirm-dialog/ConfirmDialog.test.tsx similarity index 52% rename from src/components/confirm-dialog/__tests__/ConfirmDialog.test.tsx rename to src/components/confirm-dialog/ConfirmDialog.test.tsx index 04a482f967..2f90ce6a9a 100644 --- a/src/components/confirm-dialog/__tests__/ConfirmDialog.test.tsx +++ b/src/components/confirm-dialog/ConfirmDialog.test.tsx @@ -1,9 +1,9 @@ +import { fireEvent, screen, render } from "@testing-library/react"; import React from "react"; -import { mount } from "enzyme"; -import { useConfirmDialog } from "../ConfirmDialog"; +import { useConfirmDialog } from "./ConfirmDialog"; -describe("Confirmation dialog", () => { - it("renders simple confirm dialog", () => { +describe("ConfirmDialog", () => { + it("renders a simple confirm dialog", () => { const onConfirm = jest.fn(); const Test = () => { const [toggle, ConfirmDialog] = useConfirmDialog({ @@ -13,9 +13,10 @@ describe("Confirmation dialog", () => { continueButtonLabel: "Delete", onConfirm: onConfirm, }); + return ( <> - @@ -23,13 +24,13 @@ describe("Confirmation dialog", () => { ); }; - const simple = mount(); - simple.find("#show").simulate("click"); + render(); + fireEvent.click(screen.getByTestId("show")); - const button = simple.find("#modal-confirm").find("button"); - expect(button).not.toBeNull(); + const confirmButton = screen.getByTestId("modalConfirm"); + expect(confirmButton).toBeInTheDocument(); - button!.simulate("click"); + fireEvent.click(confirmButton); expect(onConfirm).toBeCalled(); }); });