test.spec.jsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { describe, it, expect } from 'vitest';
  2. import { render, cleanup } from '@testing-library/preact'
  3. import { Icon2fa } 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(<Icon2fa/>)
  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(<Icon2fa size={48} color={"red"} stroke={4}/>)
  14. const svg = container.getElementsByTagName("svg")[0]
  15. expect(svg.getAttribute("width")).toBe("48")
  16. expect(svg.getAttribute("stroke")).toBe("red")
  17. expect(svg.getAttribute("stroke-width")).toBe("4")
  18. })
  19. it('should apply all classNames to the element', () => {
  20. const testClass = 'test-class';
  21. const { container } = render(
  22. <Icon2fa className={testClass} />,
  23. );
  24. expect(container.firstChild).toHaveClass(testClass);
  25. expect(container.firstChild).toHaveClass('tabler-icon');
  26. expect(container.firstChild).toHaveClass('tabler-icon-2fa');
  27. });
  28. it('should add a style attribute to the element', () => {
  29. const { container } = render(<Icon2fa style={{ color: "red" }}/>)
  30. const svg = container.getElementsByTagName("svg")[0]
  31. expect(svg).toHaveStyle('color: rgb(255, 0, 0)')
  32. })
  33. it("should match snapshot", () => {
  34. const { container } = render(<Icon2fa/>)
  35. expect(container.innerHTML).toMatchInlineSnapshot(`
  36. <svg xmlns="http://www.w3.org/2000/svg"
  37. width="24"
  38. height="24"
  39. viewbox="0 0 24 24"
  40. fill="none"
  41. stroke="currentColor"
  42. stroke-width="2"
  43. stroke-linecap="round"
  44. stroke-linejoin="round"
  45. class="tabler-icon tabler-icon-2fa "
  46. >
  47. <path d="M7 16h-4l3.47 -4.66a2 2 0 1 0 -3.47 -1.54">
  48. </path>
  49. <path d="M10 16v-8h4">
  50. </path>
  51. <path d="M10 12l3 0">
  52. </path>
  53. <path d="M17 16v-6a2 2 0 0 1 4 0v6">
  54. </path>
  55. <path d="M17 13l4 0">
  56. </path>
  57. </svg>
  58. `)
  59. })
  60. })