import * as React from "react"; import {render, fireEvent} from "@testing-library/react"; import {Button} from "@nextui-org/button"; import {Tooltip} from "../src"; describe("Tooltip", () => { it("should throw error if no children is passed", () => { const spy = jest.spyOn(console, "warn").mockImplementation(() => {}); render(); expect(spy).toHaveBeenCalled(); }); it("should render correctly", () => { const wrapper = render( , ); expect(() => wrapper.unmount()).not.toThrow(); }); it("ref should be forwarded", () => { const ref = React.createRef(); render( , ); expect(ref.current).not.toBeNull(); }); it("should hide the tooltip when pressing the escape key", () => { const onClose = jest.fn(); const wrapper = render( tooltip

} onClose={onClose}>
, ); const content = wrapper.getByTestId("content-test"); fireEvent.keyDown(content, {key: "Escape"}); expect(onClose).toHaveBeenCalledTimes(1); }); it("should still hide the tooltip when pressing the escape key if isDismissable is false", () => { const onClose = jest.fn(); const wrapper = render( tooltip

} isDismissable={false} onClose={onClose} >
, ); const content = wrapper.getByTestId("content-test"); fireEvent.keyDown(content, {key: "Escape"}); expect(onClose).toHaveBeenCalledTimes(1); }); });