-
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.
Integrate Vitest and Testing Library (#23)
* init * * * * * * * *fix * * * *
- Loading branch information
1 parent
fe78c1d
commit 8fefa9f
Showing
11 changed files
with
1,357 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 |
---|---|---|
|
@@ -15,3 +15,6 @@ jobs: | |
|
||
- name: Lint | ||
run: yarn lint | ||
|
||
- name: Unit Test | ||
run: yarn test:unit |
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
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,8 @@ | ||
import "@testing-library/jest-dom/vitest"; | ||
|
||
import { cleanup } from "@testing-library/react"; | ||
import { afterEach } from "vitest"; | ||
|
||
afterEach(() => { | ||
cleanup(); | ||
}); |
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,25 @@ | ||
import { fireEvent, render, screen } from "@testing-library/react"; | ||
import React from "react"; | ||
import { describe, expect, it, vi } from "vitest"; | ||
|
||
import { DifficultyButton } from "../../components/DifficultyButton"; | ||
|
||
describe("DifficultyButton", () => { | ||
it("should call changeDifficulty on click", () => { | ||
const changeDifficultyMock = vi.fn(); | ||
|
||
render( | ||
<DifficultyButton | ||
changeDifficulty={changeDifficultyMock} | ||
disabled={false} | ||
> | ||
Difficulty | ||
</DifficultyButton> | ||
); | ||
|
||
const button = screen.getByRole("button", { name: "Difficulty" }); | ||
fireEvent.click(button); | ||
|
||
expect(changeDifficultyMock).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
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,30 @@ | ||
import { act, render, screen } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import React from "react"; | ||
import { describe, expect, it, vi } from "vitest"; | ||
|
||
import { VolumeButton } from "../../components/VolumeButton"; | ||
import { useGlobalStore } from "../../store"; | ||
|
||
describe("VolumeButton", async () => { | ||
it("should display volume-icon by default", () => { | ||
render(<VolumeButton />); | ||
const volumeIcon = screen.getByTestId("volume-icon"); | ||
|
||
expect(volumeIcon).toBeInTheDocument(); | ||
}); | ||
|
||
it("should call setIsMuted & display muted-volume-icon", async () => { | ||
const setIsMutedSpy = vi.spyOn(useGlobalStore.getState(), "setIsMuted"); | ||
|
||
render(<VolumeButton />); | ||
|
||
await act(async () => { | ||
await userEvent.click(screen.getByTestId("volume-button")); | ||
}); | ||
const mutedVolumeIcon = screen.getByTestId("muted-volume-icon"); | ||
|
||
expect(setIsMutedSpy).toHaveBeenCalled(); | ||
expect(mutedVolumeIcon).toBeInTheDocument(); | ||
}); | ||
}); |
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,10 @@ | ||
import { defineConfig } from "vitest/config"; | ||
|
||
export default defineConfig({ | ||
test: { | ||
environment: "jsdom", | ||
setupFiles: "./src/tests/setup.ts", | ||
globals: true, | ||
mockReset: true, | ||
}, | ||
}); |
Oops, something went wrong.