|
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"; |
3 | 2 | import { ColorSwitch } from "./color-switch";
|
| 3 | +import { afterEach, describe, test } from "vitest"; |
| 4 | +import { useTheme } from "../../hooks/use-theme"; |
4 | 5 |
|
5 |
| -describe.concurrent("color-switch", () => { |
| 6 | +describe("color-switch", () => { |
6 | 7 | afterEach(cleanup);
|
7 | 8 |
|
8 |
| - test("check if h1 heading exists", ({ expect }) => { |
| 9 | + test("color-scheme-toggle", async ({ expect }) => { |
| 10 | + const hook = renderHook(() => useTheme()); |
9 | 11 | 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"); |
11 | 21 | });
|
12 | 22 | });
|
0 commit comments