File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ export default defineConfig({
8
8
test : {
9
9
environment : "jsdom" ,
10
10
globals : true ,
11
- setupFiles : [ ] ,
11
+ setupFiles : [ "vitest.setup.ts" ] ,
12
12
coverage : {
13
13
include : [ "src/**" ] ,
14
14
exclude : [ "src/**/index.ts" , "src/**/declaration.d.ts" ] ,
Original file line number Diff line number Diff line change
1
+ import { vi } from "vitest" ;
2
+
3
+ // mock matchMedia
4
+ Object . defineProperty ( window , "matchMedia" , {
5
+ writable : true ,
6
+ value : vi . fn ( ) . mockImplementation ( ( query : string ) => ( {
7
+ matches : query . includes ( window . media ) ,
8
+ media : query ,
9
+ onchange : null ,
10
+ addEventListener : vi . fn ( ) ,
11
+ removeEventListener : vi . fn ( ) ,
12
+ dispatchEvent : vi . fn ( ) ,
13
+ } ) ) ,
14
+ } ) ;
15
+
16
+ declare global {
17
+ interface Window {
18
+ media : "dark" | "light" ;
19
+ }
20
+ var cookies : Record < string , { value : string } > ; // eslint-disable-line no-var -- let is not supported in defining global due to block scope
21
+ var path : string ; // eslint-disable-line no-var -- let is not supported in defining global due to block scope
22
+ }
23
+ Object . defineProperty ( window , "media" , {
24
+ writable : true ,
25
+ value : "dark" ,
26
+ } ) ;
27
+
28
+ globalThis . cookies = { } ;
29
+
30
+ vi . mock ( "next/headers" , ( ) => ( {
31
+ cookies : ( ) => ( { get : ( cookieName : string ) => globalThis . cookies [ cookieName ] } ) ,
32
+ } ) ) ;
You can’t perform that action at this time.
0 commit comments