import { describe, it, expect, afterEach, expectTypeOf } from 'vitest'; import { render, cleanup } from '@testing-library/react' import { IconAccessible, IconAccessibleFilled, createReactComponent } from "./src/tabler-icons-react" describe("React Icon component", () => { afterEach(() => { cleanup(); }); it("should render icon component", () => { const { container } = render() expect(container.getElementsByTagName("svg").length).toBeGreaterThan(0) }) it("should update svg attributes when there are props passed to the component", () => { const { container } = render() const svg = container.getElementsByTagName("svg")[0] expect(svg.getAttribute("width")).toBe("48") expect(svg.getAttribute("stroke")).toBe("red") expect(svg.getAttribute("stroke-width")).toBe("4") expect(svg.getAttribute("fill")).toBe("none") }) it("should update svg attributes when there are props passed to the filled version of component", () => { const { container } = render() const svg = container.getElementsByTagName("svg")[0] expect(svg.getAttribute("width")).toBe("48") expect(svg.getAttribute("fill")).toBe("red") expect(svg.getAttribute("stroke")).toBe("none") expect(svg.getAttribute("stroke-width")).toBe(null) }) it('should apply all classNames to the element', () => { const testClass = 'test-class'; const { container } = render( , ); expect(container.firstChild).toHaveClass(testClass); expect(container.firstChild).toHaveClass('tabler-icon'); expect(container.firstChild).toHaveClass('tabler-icon-accessible'); }); it('should add a style attribute to the element', () => { const { container } = render() const svg = container.getElementsByTagName("svg")[0] expect(svg).toHaveStyle('color: rgb(255, 0, 0)') }) it('should have proper type', () => { expectTypeOf(IconAccessible).toBeFunction(); expectTypeOf(IconAccessible).toEqualTypeOf(createReactComponent('outline', 'accessible', 'Accessible', [])); }); it('should add title child element to svg when title prop is passed', () => { const { container } = render(); const svg = container.getElementsByTagName("svg")[0]; const title = svg.getElementsByTagName("title")[0]; expect(title).toHaveTextContent("Accessible Icon"); }) it("should match snapshot", () => { const { container } = render() expect(container.innerHTML).toMatchInlineSnapshot(` `) }) })