Skip to content

Commit 3edd065

Browse files
committed
test color switch
1 parent 377a6e0 commit 3edd065

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed
Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1-
import { cleanup, render, screen } from "@testing-library/react";
2-
import { afterEach, describe, test } from "vitest";
1+
import { act, cleanup, fireEvent, render, renderHook, screen } from "@testing-library/react";
32
import { ColorSwitch } from "./color-switch";
3+
import { afterEach, describe, test } from "vitest";
4+
import { useTheme } from "../../hooks/use-theme";
45

5-
describe.concurrent("color-switch", () => {
6+
describe("color-switch", () => {
67
afterEach(cleanup);
78

8-
test("check if h1 heading exists", ({ expect }) => {
9+
test("color-scheme-toggle", async ({ expect }) => {
10+
const hook = renderHook(() => useTheme());
911
render(<ColorSwitch />);
10-
expect(screen.getByTestId("color-switch-h1").textContent).toBe("color-switch");
12+
const element = screen.getByTestId("color-switch");
13+
await act(() => fireEvent.click(element));
14+
expect(hook.result.current.colorSchemePreference).toBe("dark");
15+
await act(() => fireEvent.click(element));
16+
expect(hook.result.current.colorSchemePreference).toBe("light");
17+
await act(() => fireEvent.click(element));
18+
expect(hook.result.current.colorSchemePreference).toBe("system");
19+
await act(() => fireEvent.click(element));
20+
expect(hook.result.current.colorSchemePreference).toBe("dark");
1121
});
1222
});

0 commit comments

Comments
 (0)