-
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.
Add unit test for call to action card
- Loading branch information
1 parent
a500adb
commit e384667
Showing
3 changed files
with
35 additions
and
4 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
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,31 @@ | ||
import CallToActionCard from "./index"; | ||
import { render } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
|
||
describe("Call to Action Card", () => { | ||
test("renders image, header, body and clickable button with label", () => { | ||
const onAction = jest.fn(); | ||
const { getByText, getByRole } = render( | ||
<CallToActionCard | ||
bodyText="big body baby" | ||
headingText="Heading up the West Coast" | ||
imageSrc="big_apple.png" | ||
imageAlt="An apple that is big" | ||
buttonLabel="Click Me" | ||
onAction={onAction} | ||
/> | ||
) | ||
|
||
expect(getByText("big body baby")).toBeInTheDocument(); | ||
expect(getByText("Heading up the West Coast")).toBeInTheDocument(); | ||
|
||
const image = getByRole("img"); | ||
expect(image).toHaveAttribute("src", "big_apple.png"); | ||
expect(image).toHaveAttribute("alt", "An apple that is big"); | ||
|
||
const button = getByRole("button") | ||
expect(button).toHaveTextContent("Click Me") | ||
userEvent.click(button); | ||
expect(onAction).toHaveBeenCalled(); | ||
}); | ||
}) |
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