test.spec.js 1.3 KB

1234567891011121314151617181920212223242526272829
  1. import { h } from "preact";
  2. import { render } from "@testing-library/preact";
  3. import { Icon2fa } from "./src/icons.js";
  4. describe("Preact Icon component", () => {
  5. test("should render icon component", () => {
  6. const { container } = render(<Icon2fa />);
  7. expect(container.getElementsByTagName("svg").length).toBeGreaterThan(0);
  8. });
  9. test("should update svg attributes when there are props passed to the component", () => {
  10. const { container } = render(
  11. <Icon2fa size={48} color={"red"} strokeWidth={4} />
  12. );
  13. const svg = container.getElementsByTagName("svg")[0];
  14. expect(svg.getAttribute("width")).toBe("48");
  15. expect(svg.getAttribute("stroke")).toBe("red");
  16. expect(svg.getAttribute("stroke-width")).toBe("4");
  17. });
  18. test("should match snapshot", () => {
  19. const { container } = render(<Icon2fa />);
  20. expect(container.innerHTML).toMatchInlineSnapshot(
  21. `"<svg xmlns=\\"http://www.w3.org/2000/svg\\" width=\\"24\\" height=\\"24\\" viewBox=\\"0 0 24 24\\" fill=\\"none\\" stroke=\\"currentColor\\" stroke-width=\\"2\\" stroke-linecap=\\"round\\" stroke-linejoin=\\"round\\" class=\\"tabler-icon tabler-icon-2fa\\"><path d=\\"M7 16h-4l3.47 -4.66a2 2 0 1 0 -3.47 -1.54m7 6.2v-8h4m-4 4l3 0m4 4v-6a2 2 0 0 1 4 0v6m-4 -3l4 0\\"></path></svg>"`
  22. );
  23. });
  24. });