test.spec.js 959 B

123456789101112131415161718192021222324252627
  1. import { render } from "@testing-library/react"
  2. import { Icon2fa } from "./src/icons.js"
  3. import React from "react"
  4. import renderer from 'react-test-renderer'
  5. describe("React Icon component", () => {
  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"} strokeWidth={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. // Jest creates separate file to store snapshots
  18. test("should match snapshot", () => {
  19. const icon = renderer.create(<Icon2fa/>).toJSON()
  20. expect(icon).toMatchSnapshot()
  21. })
  22. })