We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
matchMedia
1 parent 5006fce commit c9ba76dCopy full SHA for c9ba76d
jest-setup.ts
@@ -4,6 +4,22 @@ import nock from 'nock';
4
if ( typeof window !== 'undefined' ) {
5
// The ipcListener global is usually defined in preload.ts
6
window.ipcListener = { subscribe: jest.fn() };
7
+
8
+ // Mock `matchMedia` as it's not implemented in JSDOM
9
+ // Reference: https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
10
+ Object.defineProperty( window, 'matchMedia', {
11
+ writable: true,
12
+ value: jest.fn().mockImplementation( ( query ) => ( {
13
+ matches: false,
14
+ media: query,
15
+ onchange: null,
16
+ addListener: jest.fn(), // deprecated
17
+ removeListener: jest.fn(), // deprecated
18
+ addEventListener: jest.fn(),
19
+ removeEventListener: jest.fn(),
20
+ dispatchEvent: jest.fn(),
21
+ } ) ),
22
+ } );
23
}
24
25
nock.disableNetConnect();
0 commit comments