-
Notifications
You must be signed in to change notification settings - Fork 401
Expand file tree
/
Copy pathjest-setup.ts
More file actions
64 lines (52 loc) · 1.56 KB
/
jest-setup.ts
File metadata and controls
64 lines (52 loc) · 1.56 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
/* eslint-disable no-console,jest/no-standalone-expect */
import '@testing-library/jest-dom';
import '@testing-library/jest-dom/extend-expect';
import { configure as configureRTL } from '@testing-library/react';
import { noop } from 'lodash';
configureRTL({ testIdAttribute: 'data-test' });
// https://github.com/facebook/jest/issues/10784
process.on('unhandledRejection', (reason) => {
console.log(reason);
});
window.matchMedia = jest.fn(
() =>
({
matches: false,
addListener: noop,
addEventListener: noop,
removeListener: noop,
removeEventListener: noop,
} as MediaQueryList),
);
Object.defineProperty(
window.navigator,
'userAgent',
((value) => ({
get() {
return value;
},
set(v) {
value = v;
},
}))(window.navigator.userAgent),
);
(global as any).__webpack_public_path__ = undefined;
const originalConsoleError = console.error;
const originalConsoleWarn = console.warn;
beforeAll(() => {
expect.hasAssertions();
console.error = (...args: unknown[]) => {
const message = args.map(String).join();
// FIXME: Remove these ignored errors once we have enabled react 18 features
if (/Formik|createRoot|React.act|findDOMNode/.test(message)) {
return;
}
originalConsoleError(...args);
};
console.warn = (...args: unknown[]) => {
if (args.map(String).join().includes('Formik')) {
return;
}
originalConsoleWarn(...args);
};
});