Skip to content

Commit 2ae9815

Browse files
committed
Update test
1 parent 78ee3ac commit 2ae9815

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/components/Menu/Menu.test.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,22 @@ import userEvent from "@testing-library/user-event";
1717
import { getPlatform } from "../../utils/platform";
1818

1919
vi.mock("../../utils/platform", () => ({ getPlatform: vi.fn(() => "other") }));
20-
vi.spyOn(window, "matchMedia").mockReturnValue({
21-
matches: false,
22-
} as unknown as MediaQueryList);
20+
vi.hoisted(() => {
21+
Object.defineProperty(window, "matchMedia", {
22+
writable: true,
23+
enumerable: true,
24+
value: vi.fn().mockImplementation((query) => ({
25+
matches: false,
26+
media: query,
27+
onchange: null,
28+
addListener: vi.fn(), // deprecated
29+
removeListener: vi.fn(), // deprecated
30+
addEventListener: vi.fn(),
31+
removeEventListener: vi.fn(),
32+
dispatchEvent: vi.fn(),
33+
})),
34+
});
35+
});
2336

2437
async function withPlatform(
2538
platform: ReturnType<typeof getPlatform>,

0 commit comments

Comments
 (0)