test.spec.jsx 2.7 KB

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