-
Notifications
You must be signed in to change notification settings - Fork 20
/
jest-setup.ts
50 lines (44 loc) · 1.53 KB
/
jest-setup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import '@testing-library/jest-dom';
// We need this polyfill because the `ReadableStream` class is
// used by `@php-wasm/universal` and it's not available in the Jest environment.
// eslint-disable-next-line import/no-unresolved
import 'web-streams-polyfill/polyfill';
import nock from 'nock';
if ( typeof window !== 'undefined' ) {
// The ipcListener global is usually defined in preload.ts
window.ipcListener = { subscribe: jest.fn() };
// Mock `matchMedia` as it's not implemented in JSDOM
// Reference: https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
Object.defineProperty( window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation( ( query ) => ( {
matches: false,
media: query,
onchange: null,
addListener: jest.fn(), // deprecated
removeListener: jest.fn(), // deprecated
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
} ) ),
} );
}
nock.disableNetConnect();
nock.enableNetConnect( 'raw.githubusercontent.com' );
// We consider the app to be online by default.
jest.mock( './src/hooks/use-offline', () => ( {
useOffline: jest.fn().mockReturnValue( false ),
} ) );
jest.mock( './src/hooks/use-ai-icon', () => ( {
__esModule: true,
default: () => ( {
rive: jest.fn(),
RiveComponent: jest.fn(),
inactiveInput: jest.fn(),
typingInput: jest.fn(),
thinkingInput: jest.fn(),
startStateMachine: jest.fn(),
pauseStateMachine: jest.fn(),
} ),
} ) );
global.ResizeObserver = require( 'resize-observer-polyfill' );