From 352f5269cd42e3d91447914cb18098b234bd23f9 Mon Sep 17 00:00:00 2001 From: Kevin Wu Date: Thu, 7 Dec 2023 11:07:51 -0800 Subject: [PATCH] test: Add setup file, handle matchMedia (#831) --- apps/antalmanac/tests/setup/setup.ts | 15 +++++++++++++++ apps/antalmanac/vite.config.ts | 4 ++++ 2 files changed, 19 insertions(+) create mode 100644 apps/antalmanac/tests/setup/setup.ts diff --git a/apps/antalmanac/tests/setup/setup.ts b/apps/antalmanac/tests/setup/setup.ts new file mode 100644 index 000000000..69b8ee9c2 --- /dev/null +++ b/apps/antalmanac/tests/setup/setup.ts @@ -0,0 +1,15 @@ +import { vi } from 'vitest'; + +Object.defineProperty(window, 'matchMedia', { + writable: true, + value: vi.fn().mockImplementation((query) => ({ + matches: false, + media: query, + onchange: null, + addListener: vi.fn(), // deprecated + removeListener: vi.fn(), // deprecated + addEventListener: vi.fn(), + removeEventListener: vi.fn(), + dispatchEvent: vi.fn(), + })), +}); diff --git a/apps/antalmanac/vite.config.ts b/apps/antalmanac/vite.config.ts index 3f0fff255..4ff616641 100644 --- a/apps/antalmanac/vite.config.ts +++ b/apps/antalmanac/vite.config.ts @@ -23,4 +23,8 @@ export default defineConfig({ server: { host: 'localhost', }, + test: { + environment: 'jsdom', + setupFiles: [resolve(__dirname, 'tests/setup/setup.ts')], + }, });