-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetupTests.js
68 lines (59 loc) · 1.56 KB
/
setupTests.js
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import 'jest-canvas-mock';
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-preact-pure';
import * as matchers from 'jest-extended';
import ResizeObserver from 'resize-observer-polyfill';
import { TextEncoder, TextDecoder } from 'util';
import appsettings from './src/appsettings';
localStorage.clear();
appsettings.init();
Object.assign(global, { TextDecoder, TextEncoder });
global.ResizeObserver = ResizeObserver;
global.setImmediate = global.setImmediate || ((fn, ...args) => global.setTimeout(fn, 0, ...args));
global.clearImmediate = global.clearImmediate || ((...args) => global.clearTimeout(...args));
global.IntersectionObserver = class IntersectionObserver {
constructor() { }
disconnect() {
return null;
}
observe() {
return null;
}
takeRecords() {
return null;
}
unobserve() {
return null;
}
};
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(),
})),
});
expect.extend(matchers);
configure({ adapter: new Adapter() });
jest.mock('react-i18next', () => ({
withNamespaces: () => Component => {
Component.defaultProps = {
...Component.defaultProps,
t: (i18nKey) => i18nKey,
i18n: {
changeLanguage: () => new Promise(() => { }),
},
};
return Component;
},
reactI18nextModule: {
type: '3rdParty',
init: jest.fn(),
},
}));