-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(empty-state) test improvements following code review
- Loading branch information
Showing
1 changed file
with
12 additions
and
11 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,45 +1,46 @@ | ||
import { render } from "@testing-library/react"; | ||
import { render, screen } from "@testing-library/react"; | ||
import React from "react"; | ||
|
||
import EmptyState from "./EmptyState"; | ||
|
||
describe("EmptyState ", () => { | ||
it("renders the title", () => { | ||
const { container } = render( | ||
<EmptyState title="Test title" image={<img alt="" src="" />} /> | ||
); | ||
expect(container).toContainHTML("Test title"); | ||
render(<EmptyState title="Test title" image={<img alt="" src="" />} />); | ||
expect( | ||
screen.getByRole("heading", { name: "Test title" }) | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it("renders the image", () => { | ||
const { container } = render( | ||
render( | ||
<EmptyState | ||
title="Test title" | ||
image={<img alt="" src="path/to/image" />} | ||
/> | ||
); | ||
expect(container).toContainHTML("path/to/image"); | ||
expect(screen.getByRole("img")).toHaveAttribute("src", "path/to/image"); | ||
}); | ||
|
||
it("renders the content", () => { | ||
const { container } = render( | ||
render( | ||
<EmptyState title="Test title" image={<img alt="" src="" />}> | ||
Empty | ||
</EmptyState> | ||
); | ||
expect(container).toContainHTML("Empty"); | ||
expect(screen.getByText("Empty")).toBeInTheDocument(); | ||
}); | ||
|
||
it("passes extra classes to the wrapping element", async () => { | ||
const { container } = render( | ||
render( | ||
<EmptyState | ||
title="Test title" | ||
image={<img alt="" src="" />} | ||
className="extra-class" | ||
data-testid="wrapper" | ||
> | ||
Empty | ||
</EmptyState> | ||
); | ||
expect(container).toContainHTML('div class="extra-class"'); | ||
expect(screen.getByTestId("wrapper")).toHaveClass("extra-class"); | ||
}); | ||
}); |