import { createRef } from "react"; import { render, screen } from "@testing-library/react"; import { SVG } from "."; const CLASS_NAME = "mobius-svg"; const SvgImage = ( ); describe("Test for SVG", () => { it("should render without errors", () => { render({SvgImage}); }); describe("uses correct class names", () => { it("uses Mobius class", () => { render({SvgImage}); expect(screen.getByTestId("test")).toHaveClass("mobius"); }); it("uses base Mobius class", () => { render({SvgImage}); expect(screen.getByTestId("test")).toHaveClass(CLASS_NAME); }); it("includes custom class name", () => { render( {SvgImage} , ); expect(screen.getByTestId("test")).toHaveClass("my-class"); expect(screen.getByTestId("test")).toHaveClass(CLASS_NAME); }); }); describe("semantic HTML and accessibility", () => { it("renders an element", () => { const { container } = render({SvgImage}); expect(container.firstChild?.nodeName).toBe("svg"); }); it("preserves the viewBox attribute from the child SVG", () => { render({SvgImage}); expect(screen.getByTestId("test")).toHaveAttribute( "viewBox", "0 0 299.8 85", ); }); it("preserves the xmlns attribute from the child SVG", () => { render({SvgImage}); expect(screen.getByTestId("test")).toHaveAttribute( "xmlns", "http://www.w3.org/2000/svg", ); }); // Note: SVG component does not set role="img" or support a title prop. // For decorative SVGs this is acceptable, but meaningful SVGs should // have role="img" and an accessible label (aria-label or ). // The component's type interface (SVGProps) also does not accept role or // aria-label, so consumers cannot pass these props without a type error. it("does not set role='img' by default", () => { render({SvgImage}); expect(screen.getByTestId("test")).not.toHaveAttribute("role"); }); }); it("forwards ref", () => { const ref = createRef(); render({SvgImage}); expect(ref.current).toBeInstanceOf(SVGSVGElement); }); });