-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathjest-setup.ts
More file actions
70 lines (61 loc) · 1.81 KB
/
jest-setup.ts
File metadata and controls
70 lines (61 loc) · 1.81 KB
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
69
70
import '@testing-library/jest-dom';
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import baseZhCN from './packages/base/src/locale/zh-CN';
import sqleZhCN from './packages/sqle/src/locale/zh-CN';
import commonZhCN from './packages/dms-kit/src/locale/zh-CN';
import Adapter from '@cfaester/enzyme-adapter-react-18';
import * as Enzyme from 'enzyme';
import 'jest-canvas-mock';
jest.mock('rehype-sanitize', () => () => jest.fn());
Enzyme.configure({ adapter: new Adapter() });
Object.defineProperty(global, 'matchMedia', {
writable: true,
value: (query: any) => {
return {
matches: false,
media: query,
onchange: null,
addListener: jest.fn(), // deprecated
removeListener: jest.fn(), // deprecated
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn()
};
}
});
i18n.use(initReactI18next).init({
resources: {
'zh-CN': {
translation: {
...baseZhCN.translation,
...sqleZhCN.translation,
...commonZhCN.translation
}
}
},
lng: 'zh-CN',
fallbackLng: 'zh-CN',
interpolation: {
escapeValue: false
}
});
const ignoreReactConsoleErrors = () => {
const rules = [
'Warning: findDOMNode is deprecated and will be removed in the next major release. Instead, add a ref directly to the element you want to reference. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-find-nod'
];
const originalError = console.error;
beforeAll(() => {
console.error = (...arg) => {
if (typeof arg[0] === 'string' && rules.some((v) => arg[0].includes(v))) {
return;
}
originalError(...arg);
};
});
afterAll(() => {
console.error = originalError;
});
};
ignoreReactConsoleErrors();
jest.setTimeout(60 * 1000);