-
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.
feat: test setup and GifItem unit testing
- Loading branch information
Showing
9 changed files
with
2,948 additions
and
67 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
presets: [ | ||
["@babel/preset-env", { targets: { esmodules: true } }], | ||
["@babel/preset-react", { runtime: "automatic" }], | ||
], | ||
}; |
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,4 @@ | ||
module.exports = { | ||
testEnvironment: "jest-environment-jsdom", | ||
setupFiles: ["./jest.setup.js"], | ||
}; |
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,2 @@ | ||
// In case of needing the FetchAPI implementation | ||
import "whatwg-fetch"; // <-- yarn add whatwg-fetch |
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
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,22 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import GifItem from "../../src/components/GifItem"; | ||
describe("GifItem", () => { | ||
const title = "Title"; | ||
const url = "https://url.com/"; | ||
test("should match the snapshot", () => { | ||
const { container } = render(<GifItem title={title} url={url} />); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
test("should show the gif with the right url and alt props", () => { | ||
render(<GifItem title={title} url={url} />); | ||
const { src, alt } = screen.getByRole("img"); | ||
expect(src).toBe(url); | ||
expect(alt).toBe(title); | ||
}); | ||
|
||
test("should show the title in the component", () => { | ||
render(<GifItem title={title} url={url} />); | ||
expect(screen.getByText(title)).toBeTruthy(); | ||
}); | ||
}); |
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,17 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`GifItem should match the snapshot 1`] = ` | ||
<div> | ||
<div | ||
class="card" | ||
> | ||
<img | ||
alt="Title" | ||
src="https://url.com/" | ||
/> | ||
<p> | ||
Title | ||
</p> | ||
</div> | ||
</div> | ||
`; |
Oops, something went wrong.