import { Tooltip } from "./index"; import { render, screen } from "@testing-library/react"; describe("Tooltip", () => { it("renders children", () => { render(Hover me); expect(screen.getByText("Hover me")).toBeInTheDocument(); }); it("sets data-text attribute with tooltip message", () => { render(Content); const span = screen.getByText("Content"); expect(span).toHaveAttribute("data-text", "Helpful tip"); }); it("applies tooltip-custom class to the span", () => { render(Child); const span = screen.getByText("Child"); expect(span).toHaveClass("tooltip-custom"); }); it("applies custom className when provided", () => { render( Child ); const span = screen.getByText("Child"); expect(span).toHaveClass("tooltip-custom"); expect(span).toHaveClass("extra-class"); }); it("does not add undefined to class when className is not provided", () => { render(Child); const span = screen.getByText("Child"); expect(span.className).not.toContain("undefined"); }); it("injects a style element", () => { const { container } = render(Child); const style = container.querySelector("style"); expect(style).toBeInTheDocument(); expect(style?.textContent).toContain(".tooltip-custom"); }); it("has the correct displayName", () => { expect(Tooltip.displayName).toBe("Tooltip"); }); });