test.spec.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { render, fireEvent } from "@testing-library/vue";
  2. import { IconActivity } from "./";
  3. describe("Vue Icon component", () => {
  4. it("should render an component", () => {
  5. const { container } = render(IconActivity);
  6. expect(container.innerHTML).toMatchInlineSnapshot(
  7. `"<svg xmlns=\\"http://www.w3.org/2000/svg\\" width=\\"24\\" height=\\"24\\" viewBox=\\"0 0 24 24\\" fill=\\"none\\" stroke=\\"currentColor\\" stroke-width=\\"2\\" stroke-linecap=\\"round\\" stroke-linejoin=\\"round\\" class=\\"tabler-icon tabler-icon-activity\\"><path stroke=\\"none\\" d=\\"M0 0h24v24H0z\\" fill=\\"none\\"></path><path d=\\"M3 12h4l3 8l4 -16l3 8h4\\"></path></svg>"`
  8. );
  9. });
  10. it("should adjust the size, stroke color and stroke width", () => {
  11. const { container } = render(IconActivity, {
  12. props: {
  13. size: 48,
  14. color: "red",
  15. "stroke-width": 4,
  16. },
  17. });
  18. const [icon] = container.getElementsByTagName('svg')
  19. expect(icon.getAttribute("width")).toBe("48");
  20. expect(icon.getAttribute("stroke")).toBe("red");
  21. expect(icon.getAttribute("stroke-width")).toBe("4");
  22. expect(container.innerHTML).toMatchInlineSnapshot(
  23. `"<svg xmlns=\\"http://www.w3.org/2000/svg\\" width=\\"48\\" height=\\"48\\" viewBox=\\"0 0 24 24\\" fill=\\"none\\" stroke=\\"red\\" stroke-width=\\"4\\" stroke-linecap=\\"round\\" stroke-linejoin=\\"round\\" size=\\"48\\" color=\\"red\\" class=\\"tabler-icon tabler-icon-activity\\"><path stroke=\\"none\\" d=\\"M0 0h24v24H0z\\" fill=\\"none\\"></path><path d=\\"M3 12h4l3 8l4 -16l3 8h4\\"></path></svg>"`
  24. );
  25. });
  26. it("should add a class to the element", () => {
  27. const { container } = render(IconActivity, {
  28. attrs: {
  29. class: "my-icon",
  30. },
  31. });
  32. expect(container.innerHTML).toMatchInlineSnapshot(
  33. `"<svg xmlns=\\"http://www.w3.org/2000/svg\\" width=\\"24\\" height=\\"24\\" viewBox=\\"0 0 24 24\\" fill=\\"none\\" stroke=\\"currentColor\\" stroke-width=\\"2\\" stroke-linecap=\\"round\\" stroke-linejoin=\\"round\\" class=\\"my-icon\\"><path stroke=\\"none\\" d=\\"M0 0h24v24H0z\\" fill=\\"none\\"></path><path d=\\"M3 12h4l3 8l4 -16l3 8h4\\"></path></svg>"`
  34. );
  35. const [icon] = container.getElementsByTagName('svg')
  36. expect(icon.getAttribute("class")).toBe("my-icon");
  37. });
  38. it("should add a style attribute to the element", () => {
  39. const { container } = render(IconActivity, {
  40. attrs: {
  41. style: "position: absolute",
  42. },
  43. });
  44. expect(container).toMatchInlineSnapshot(`
  45. <div>
  46. <svg
  47. class="tabler-icon tabler-icon-activity"
  48. fill="none"
  49. height="24"
  50. stroke="currentColor"
  51. stroke-linecap="round"
  52. stroke-linejoin="round"
  53. stroke-width="2"
  54. style="position: absolute;"
  55. viewBox="0 0 24 24"
  56. width="24"
  57. xmlns="http://www.w3.org/2000/svg"
  58. >
  59. <path
  60. d="M0 0h24v24H0z"
  61. fill="none"
  62. stroke="none"
  63. />
  64. <path
  65. d="M3 12h4l3 8l4 -16l3 8h4"
  66. />
  67. </svg>
  68. </div>
  69. `);
  70. const [icon] = container.getElementsByTagName('svg')
  71. expect(icon.getAttribute("style")).toBe("position: absolute;");
  72. });
  73. it("should call the onClick event", async () => {
  74. const onClick = jest.fn();
  75. const { container } = render(IconActivity, {
  76. attrs: {
  77. onClick,
  78. },
  79. });
  80. const [icon] = container.getElementsByClassName("tabler-icon");
  81. await fireEvent.click(icon);
  82. expect(onClick).toHaveBeenCalled();
  83. });
  84. });