-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6cd3b36
commit f07943d
Showing
4 changed files
with
83 additions
and
35 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,7 +1,52 @@ | ||
import {render, screen} from "@testing-library/react" | ||
import Heading from "components/Heading" | ||
import {render, screen} from "test-utils/render" | ||
|
||
test("renders", () => { | ||
render(<Heading />) | ||
expect(screen.getByText("Heading")) | ||
test("shows level one", () => { | ||
const {container} = render(<Heading level={1}>Heading one</Heading>) | ||
|
||
expect(container.querySelector("h1")) | ||
expect(screen.getByText("Heading one")).toHaveAttribute("id", "heading-one") | ||
|
||
expect(screen.getByLabelText("link").parentElement).toHaveAttribute( | ||
"href", | ||
"#heading-one", | ||
) | ||
}) | ||
|
||
test("shows level two", () => { | ||
const {container} = render(<Heading level={2}>Heading two</Heading>) | ||
|
||
expect(container.querySelector("h2")) | ||
expect(screen.getByText("Heading two")).toHaveAttribute("id", "heading-two") | ||
|
||
expect(screen.getByLabelText("link").parentElement).toHaveAttribute( | ||
"href", | ||
"#heading-two", | ||
) | ||
}) | ||
|
||
test("shows level three", () => { | ||
const {container} = render(<Heading level={3}>Heading three</Heading>) | ||
|
||
expect(container.querySelector("h3")) | ||
|
||
expect(screen.getByText("Heading three")).toHaveAttribute( | ||
"id", | ||
"heading-three", | ||
) | ||
|
||
expect(screen.getByLabelText("link").parentElement).toHaveAttribute( | ||
"href", | ||
"#heading-three", | ||
) | ||
}) | ||
|
||
test("overrides id", () => { | ||
render( | ||
<Heading level={1} id="custom"> | ||
Heading one | ||
</Heading>, | ||
) | ||
|
||
expect(screen.getByText("Heading one")).toHaveAttribute("id", "custom") | ||
}) |
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
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.