import { render, fireEvent } from "@testing-library/react"; import…
- User
import { render, fireEvent } from "@testing-library/react"; import ButtonsCopyAndDownload from "./index"; import { copyEmail } from "../../Utils"; import { open } from "../../../state/slices/modalSlice/modalSlice"; import { Provider } from "react-redux"; import { store } from "../../../state/store"; jest.mock("../../Utils", () => ({ copyEmail: jest.fn(), }));
jest.mock("../../../state/slices/modalSlice/modalSlice", () => ({ open: jest.fn(), }));
jest.mock("../../Hooks", () => ({ useChangeCopiedStateToDefaultAfter: () => [false, jest.fn()], }));
describe("ButtonsCopyAndDownload", () => { afterEach(() => { jest.clearAllMocks(); });
test("calls copyEmail function when copy button is clicked", () => { const { getByText } = render( ); const copyButton = getByText("Copy e-mail");
codefireEvent.click(copyButton); expect(copyEmail).toHaveBeenCalledTimes(1);});
test("calls dispatch function with open action creator when download button is clicked", () => { const { getByText } = render( ); const downloadButton = getByText("Download CV");
codefireEvent.click(downloadButton); expect(open).toHaveBeenCalledTimes(1);}); });| import Clipboard from "react-clipboard-animation"; import { copyEmail } from "../../Utils"; import { useAppSelector, useAppDispatch } from "../../../state/store"; import { open } from "../../../state/slices/modalSlice/modalSlice"; import { useChangeCopiedStateToDefaultAfter } from "../../Hooks"; const ButtonsCopyAndDownload = () => { const state = useAppSelector((state) => state.data); const dispatch = useAppDispatch(); const [copied, setCopied] = useChangeCopiedStateToDefaultAfter(1000); return ( <button onClick={() => { setCopied(true); copyEmail(state.email); }} > Copy e-mail <Clipboard style={{ width: "100px" }} copied={copied} setCopied={setCopied} text={state.email} color="black" />
code<button onClick={() => dispatch(open())}> <strong>Download CV</strong> </button> </article>); }; export default ButtonsCopyAndDownload; why second test doesn't work
- Assistant