Skip to content

Commit

Permalink
Add tests for ButtonLink component
Browse files Browse the repository at this point in the history
This commit introduces tests for the ButtonLink component to validate three main functionalities: display of children as text, the rendering of a link, and ensuring the link points to the correct target.
  • Loading branch information
josch87 committed Jun 9, 2024
1 parent b6441db commit aaa54f3
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions frontend/src/components/ButtonLink/ButtonLink.component.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { render, screen } from "@testing-library/react";
import "@testing-library/jest-dom";
import ButtonLink from "./ButtonLink.tsx";
import { MemoryRouter } from "react-router-dom";

test("ButtonLink component displays children as text", () => {
render(
<MemoryRouter>
<ButtonLink href="/my-url">Click here</ButtonLink>
</MemoryRouter>
);
const text = screen.getByText(/click here/i);
expect(text).toBeInTheDocument();
});

test("ButtonLink component displays a link", () => {
render(
<MemoryRouter>
<ButtonLink href="/my-url">Click here</ButtonLink>
</MemoryRouter>
);
const button = screen.getByRole("link");
expect(button).toBeInTheDocument();
});

test("ButtonLink component links to the correct target", () => {
render(
<MemoryRouter>
<ButtonLink href="/my-url">Click here</ButtonLink>
</MemoryRouter>
);
const button = screen.getByRole("link");
expect(button).toHaveAttribute("href", "/my-url");
});

0 comments on commit aaa54f3

Please sign in to comment.