Skip to content

Commit

Permalink
test: Add setup file, handle matchMedia (#831)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinWu098 authored Dec 7, 2023
1 parent 0e5487f commit 352f526
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions apps/antalmanac/tests/setup/setup.ts
Original file line number Diff line number Diff line change
@@ -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(),
})),
});
4 changes: 4 additions & 0 deletions apps/antalmanac/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ export default defineConfig({
server: {
host: 'localhost',
},
test: {
environment: 'jsdom',
setupFiles: [resolve(__dirname, 'tests/setup/setup.ts')],
},
});

0 comments on commit 352f526

Please sign in to comment.