-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
frontend/src/components/ButtonLink/ButtonLink.component.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); |