import { render, screen } from "@testing-library/react";
import { VisuallyHidden } from "./VisuallyHidden";
describe("VisuallyHidden", () => {
it("renders children", () => {
render(Hidden text);
expect(screen.getByText("Hidden text")).toBeInTheDocument();
});
it("applies hiding styles", () => {
render(Content);
const el = screen.getByTestId("hidden");
expect(el).toHaveStyle({ position: "absolute" });
expect(el).toHaveStyle({ width: "1px" });
expect(el).toHaveStyle({ height: "1px" });
expect(el).toHaveStyle({ overflow: "hidden" });
});
it("forwards custom className", () => {
render(
Content
,
);
expect(screen.getByTestId("hidden")).toHaveClass("custom");
});
it("renders as div by default", () => {
render(Content);
expect(screen.getByTestId("hidden").tagName).toBe("DIV");
});
it("changes element type with elementType prop", () => {
render(
Content
,
);
expect(screen.getByTestId("hidden").tagName).toBe("SPAN");
});
it("forwards role prop", () => {
render(
Content
,
);
expect(screen.getByTestId("hidden")).toHaveAttribute("role", "status");
});
it("forwards id prop", () => {
render(
Content
,
);
expect(screen.getByTestId("hidden")).toHaveAttribute("id", "my-id");
});
});