-
Notifications
You must be signed in to change notification settings - Fork 323
/
jest-setup.ts
42 lines (34 loc) · 1.04 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
// @ts-nocheck
import '@shopify/react-testing';
import '@shopify/react-testing/matchers';
import './scripts/polyfillWebRuntime';
// TODO remove all these mocks when @shopify/react-testing supports React 18 experimental
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
globalThis.scrollTo = () => null;
jest.mock('react-dom', () => {
const reactDom = jest.requireActual('react-dom');
const reactDomClient = jest.requireActual('react-dom/client');
return {
...reactDom,
render: (app, container) => {
// @ts-ignore
const root = reactDomClient.createRoot(container);
container.__unmount = root.unmount.bind(root);
root.render(app);
},
unmountComponentAtNode(container) {
container.__unmount();
},
};
});
jest.mock('@shopify/react-testing/build/cjs/compat.js', () => {
return {
getInternals: (instance: any) => {
const internals = instance._reactInternals;
if (internals) {
internals.alternate = internals.alternate || internals;
}
return internals;
},
};
});