test.spec.js 2.8 KB

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