-
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.
chore: setup vitest and react testing library, add pre-push hook
- Loading branch information
Showing
8 changed files
with
805 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#!/bin/sh | ||
pnpm lint | ||
pnpm test:ci |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,35 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import Avatar from "./Avatar"; | ||
|
||
const imageUrl = | ||
"https://gravatar.com/avatar/c8cf6521c193fc743c7fadcd8be04e983724764efa65b3c3913b6d22f086a11f?s=200&r=g&d=robohash"; | ||
|
||
describe("Avatar Component", () => { | ||
it("renders image correctly", () => { | ||
render( | ||
<Avatar> | ||
<img alt="avatar" src={imageUrl} width={40} height={40} /> | ||
</Avatar>, | ||
); | ||
|
||
const image = screen.getByRole("img", { name: /avatar/i }); | ||
|
||
expect(image).toBeInTheDocument(); | ||
}); | ||
|
||
it("handles transparent avatars", () => { | ||
render( | ||
<Avatar> | ||
<img alt="avatar" src={imageUrl} width={40} height={40} /> | ||
</Avatar>, | ||
); | ||
|
||
const image: HTMLImageElement = screen.getByRole("img", { | ||
name: /avatar/i, | ||
}); | ||
|
||
const avatarElement = image.parentElement; | ||
|
||
expect(avatarElement).toHaveClass("bg-base-200"); | ||
}); | ||
}); |
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 @@ | ||
import "@testing-library/jest-dom"; |
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,13 @@ | ||
import { defineConfig, mergeConfig } from "vitest/config"; | ||
import viteConfig from "./vite.config"; | ||
|
||
export default mergeConfig( | ||
viteConfig, | ||
defineConfig({ | ||
test: { | ||
globals: true, | ||
environment: "jsdom", | ||
setupFiles: "./src/setupTest.ts", | ||
}, | ||
}), | ||
); |