From 9abd73b2128eba81427e03a352e5b0cdfd09cba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Sat, 10 Jun 2023 00:55:10 +0100 Subject: [PATCH] test: mock `matchMedia` --- src/test-utils/setup-jest.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/test-utils/setup-jest.ts b/src/test-utils/setup-jest.ts index a604363..b93e9b1 100644 --- a/src/test-utils/setup-jest.ts +++ b/src/test-utils/setup-jest.ts @@ -15,3 +15,17 @@ if (!global.Worker) { } }; } + +Object.defineProperty(window, 'matchMedia', { + writable: true, + value: (query: string) => ({ + matches: false, + media: query, + onchange: null, + addListener: vi.fn(), // deprecated + removeListener: vi.fn(), // deprecated + addEventListener: vi.fn(), + removeEventListener: vi.fn(), + dispatchEvent: vi.fn(), + }), +});