1+ const fs = require ( 'fs/promises' )
2+
3+ Object . defineProperty ( document , 'queryCommandSupported' , {
4+ value : jest . fn ( ) . mockImplementation ( ( ) => true ) ,
5+ } ) ;
6+
7+ Object . defineProperty ( window , 'matchMedia' , {
8+ writable : true ,
9+ value : jest . fn ( ) . mockImplementation ( query => ( {
10+ matches : false ,
11+ media : query ,
12+ onchange : null ,
13+ addListener : jest . fn ( ) , // Deprecated
14+ removeListener : jest . fn ( ) , // Deprecated
15+ addEventListener : jest . fn ( ) ,
16+ removeEventListener : jest . fn ( ) ,
17+ dispatchEvent : jest . fn ( ) ,
18+ } ) ) ,
19+ } ) ;
20+
21+ Object . defineProperty ( window , 'fetch' , {
22+ value : jest . fn ( async ( path ) => {
23+
24+ const content = await fs . readFile ( path )
25+ return {
26+ json : async ( ) => JSON . stringify ( JSON . parse ( content . toString ( ) ) ) ,
27+ arrayBuffer : async ( ) => content . buffer . slice ( content . byteOffset , content . byteOffset + content . byteLength )
28+ }
29+ } )
30+ } )
31+
32+ Object . defineProperty ( URL , 'createObjectURL' , {
33+ value : jest . fn ( ( blob ) => {
34+
35+ return null
36+ } )
37+ } )
38+
39+ Object . defineProperty ( window , 'Worker' , {
40+ value : class Worker {
41+ constructor ( stringUrl ) { }
42+ postMessage ( msg ) { }
43+ terminate ( ) { }
44+ }
45+ } )
46+
47+ Object . defineProperty ( window , 'ResizeObserver' , {
48+ value : class ResizeObserver {
49+ constructor ( stringUrl ) { }
50+ observe ( ) { }
51+ }
52+ } )
0 commit comments