test.spec.jsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { describe, it, expect } from 'vitest'
  2. import Preact from 'preact'
  3. import { render } from "@testing-library/preact"
  4. import { IconActivity } from "@tabler/icons-preact"
  5. describe("Preact Icon component", () => {
  6. it("should render an component", () => {
  7. const { container } = render(<IconActivity />);
  8. expect(container.innerHTML).toMatchInlineSnapshot(
  9. `"<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-IconActivity\\"><path d=\\"M3 12h4l3 8l4 -16l3 8h4\\"></path></svg>"`
  10. );
  11. });
  12. it("should adjust the size, stroke color and stroke width", () => {
  13. const testId = "icon";
  14. const { container, getByTestId } = render(
  15. <IconActivity
  16. data-testid={testId}
  17. size={48}
  18. stroke="red"
  19. strokeWidth={4}
  20. className={"icon-class"}
  21. />
  22. );
  23. const { attributes } = getByTestId(testId);
  24. expect(attributes.stroke.value).toBe("red");
  25. expect(attributes.width.value).toBe("48");
  26. expect(attributes.height.value).toBe("48");
  27. expect(attributes["stroke-width"].value).toBe("4");
  28. expect(container.innerHTML).toMatchInlineSnapshot(
  29. `"<svg xmlns=\\"http://www.w3.org/2000/svg\\" width=\\"48\\" height=\\"48\\" viewBox=\\"0 0 24 24\\" fill=\\"none\\" stroke=\\"red\\" stroke-width=\\"4\\" stroke-linecap=\\"round\\" stroke-linejoin=\\"round\\" class=\\"icon-class\\" data-testid=\\"icon\\"><path d=\\"M3 12h4l3 8l4 -16l3 8h4\\"></path></svg>"`
  30. );
  31. });
  32. });