test.spec.jsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { describe, it, expect } from 'vitest';
  2. import { render, cleanup } from '@solidjs/testing-library'
  3. import { Icon2fa } from "./src/tabler-icons-solidjs"
  4. describe("Solidjs Icon component", () => {
  5. afterEach(() => cleanup())
  6. test("should render icon component", () => {
  7. const { container } = render(() => <Icon2fa />)
  8. expect(container.getElementsByTagName("svg").length).toBeGreaterThan(0);
  9. })
  10. test("should update svg attributes when there are props passed to the component", () => {
  11. const { container } = render(() => <Icon2fa size={48} color="red" stroke-width="4" />)
  12. const svg = container.getElementsByTagName("svg")[0]
  13. expect(svg.getAttribute("width")).toBe("48")
  14. expect(svg.getAttribute("stroke")).toBe("red")
  15. expect(svg.getAttribute("stroke-width")).toBe("4")
  16. })
  17. it('should add a class to the element', () => {
  18. const { container } = render(() => <Icon2fa class="test-class" />)
  19. const svg = container.getElementsByTagName("svg")[0]
  20. expect(svg).toHaveClass('test-class')
  21. expect(svg).toHaveClass('tabler-icon')
  22. expect(svg).toHaveClass('tabler-icon-2fa')
  23. })
  24. it('should add a style attribute to the element', () => {
  25. const { container } = render(() => <Icon2fa style="color: red" />)
  26. const svg = container.getElementsByTagName("svg")[0]
  27. expect(svg).toHaveStyle('color: rgb(255, 0, 0)')
  28. })
  29. test("should match snapshot", () => {
  30. const { container } = render(() => <Icon2fa />)
  31. expect(container.innerHTML).toMatchInlineSnapshot(`
  32. <svg xmlns="http://www.w3.org/2000/svg"
  33. width="24"
  34. height="24"
  35. viewbox="0 0 24 24"
  36. fill="none"
  37. stroke="currentColor"
  38. stroke-width="2"
  39. stroke-linecap="round"
  40. stroke-linejoin="round"
  41. class="tabler-icon tabler-icon-2fa "
  42. >
  43. <path d="M7 16h-4l3.47 -4.66a2 2 0 1 0 -3.47 -1.54">
  44. </path>
  45. <path d="M10 16v-8h4">
  46. </path>
  47. <path d="M10 12l3 0">
  48. </path>
  49. <path d="M17 16v-6a2 2 0 0 1 4 0v6">
  50. </path>
  51. <path d="M17 13l4 0">
  52. </path>
  53. </svg>
  54. `)
  55. })
  56. })