test.spec.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { describe, it, expect, afterEach } from 'vitest';
  2. import { render, cleanup } from '@testing-library/preact'
  3. import { IconAccessible, IconAccessibleFilled } from "./src/tabler-icons-preact"
  4. describe("Preact Icon component", () => {
  5. afterEach(() => {
  6. cleanup();
  7. });
  8. it("should render icon component", () => {
  9. const { container } = render(<IconAccessible/>)
  10. expect(container.getElementsByTagName("svg").length).toBeGreaterThan(0)
  11. })
  12. it("should update svg attributes when there are props passed to the component", () => {
  13. const { container } = render(<IconAccessible size={48} color={"red"} stroke={4}/>)
  14. const svg = container.getElementsByTagName("svg")[0]
  15. expect(svg.getAttribute("width")).toBe("48")
  16. expect(svg.getAttribute("fill")).toBe("none")
  17. expect(svg.getAttribute("stroke")).toBe("red")
  18. expect(svg.getAttribute("stroke-width")).toBe("4")
  19. })
  20. it("should update svg attributes when there are props passed to the filled version of component", () => {
  21. const { container } = render(<IconAccessibleFilled size={48} color={"red"}/>)
  22. const svg = container.getElementsByTagName("svg")[0]
  23. expect(svg.getAttribute("width")).toBe("48")
  24. expect(svg.getAttribute("fill")).toBe("red")
  25. expect(svg.getAttribute("stroke")).toBe("none")
  26. expect(svg.getAttribute("stroke-width")).toBe(null)
  27. })
  28. it('should apply all classNames to the element', () => {
  29. const testClass = 'test-class';
  30. const { container } = render(
  31. <IconAccessible className={testClass} />,
  32. );
  33. expect(container.firstChild).toHaveClass(testClass);
  34. expect(container.firstChild).toHaveClass('tabler-icon');
  35. expect(container.firstChild).toHaveClass('tabler-icon-accessible');
  36. });
  37. it('should add a style attribute to the element', () => {
  38. const { container } = render(<IconAccessible style={{ color: "red" }}/>)
  39. const svg = container.getElementsByTagName("svg")[0]
  40. expect(svg).toHaveStyle('color: rgb(255, 0, 0)')
  41. })
  42. it("should match snapshot", () => {
  43. const { container } = render(<IconAccessible/>)
  44. expect(container.innerHTML).toMatchInlineSnapshot(`
  45. <svg xmlns="http://www.w3.org/2000/svg"
  46. width="24"
  47. height="24"
  48. viewbox="0 0 24 24"
  49. fill="none"
  50. stroke="currentColor"
  51. stroke-width="2"
  52. stroke-linecap="round"
  53. stroke-linejoin="round"
  54. class="tabler-icon tabler-icon-accessible "
  55. >
  56. <path d="M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0">
  57. </path>
  58. <path d="M10 16.5l2 -3l2 3m-2 -3v-2l3 -1m-6 0l3 1">
  59. </path>
  60. <circle cx="12"
  61. cy="7.5"
  62. r=".5"
  63. fill="currentColor"
  64. >
  65. </circle>
  66. </svg>
  67. `)
  68. })
  69. })