test.spec.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { describe, it, expect, afterEach } from 'vitest';
  2. import { render, cleanup } from "@testing-library/svelte";
  3. import { Icon2fa } from "./src/tabler-icons-svelte";
  4. describe("Svelte Icon component", () => {
  5. afterEach(() => cleanup())
  6. it("should render icon component", () => {
  7. const { container } = render(Icon2fa);
  8. expect(container.getElementsByTagName("svg").length).toBeGreaterThan(0);
  9. });
  10. it('should add a class to the element', () => {
  11. const { container } = render(Icon2fa, {
  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-2fa')
  20. })
  21. it('should add a style attribute to the element', () => {
  22. const { container } = render(Icon2fa, {
  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(Icon2fa, {
  32. size: 48,
  33. color: "red",
  34. strokeWidth: 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 match snapshot", () => {
  42. const { container } = render(Icon2fa);
  43. expect(container.innerHTML).toMatchInlineSnapshot(`
  44. <div>
  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-2fa "
  55. >
  56. <path d="M7 16h-4l3.47 -4.66a2 2 0 1 0 -3.47 -1.54">
  57. </path>
  58. <path d="M10 16v-8h4">
  59. </path>
  60. <path d="M10 12l3 0">
  61. </path>
  62. <path d="M17 16v-6a2 2 0 0 1 4 0v6">
  63. </path>
  64. <path d="M17 13l4 0">
  65. </path>
  66. </svg>
  67. </div>
  68. `);
  69. });
  70. });