Logo.test.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. import { render, screen } from "@testing-library/react";
  2. import { describe, expect, it } from "vitest";
  3. import { Logo } from "./Logo";
  4. describe("Logo", () => {
  5. it("renders an image with alt text", () => {
  6. render(<Logo />);
  7. const img = screen.getByAltText("Jenado Unlimited");
  8. expect(img).toBeInTheDocument();
  9. });
  10. it("wraps in a link by default", () => {
  11. render(<Logo />);
  12. const link = screen.getByRole("link", { name: "Jenado Unlimited" });
  13. expect(link).toHaveAttribute("href", "/");
  14. });
  15. it("does not wrap in a link when link=false", () => {
  16. render(<Logo link={false} />);
  17. // There should be no link wrapping the logo
  18. const links = screen.queryAllByRole("link");
  19. // Filter to those that would contain our logo image
  20. const logoLinks = links.filter(
  21. (l) => l.getAttribute("aria-label") === "Jenado Unlimited",
  22. );
  23. expect(logoLinks.length).toBe(0);
  24. });
  25. it("shows text when withText is true", () => {
  26. render(<Logo withText />);
  27. expect(screen.getByText("Jenado Unlimited")).toBeInTheDocument();
  28. });
  29. });