-
Notifications
You must be signed in to change notification settings - Fork 400
Expand file tree
/
Copy pathjest-setup.ts
More file actions
73 lines (60 loc) · 1.86 KB
/
jest-setup.ts
File metadata and controls
73 lines (60 loc) · 1.86 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
71
72
73
/* 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';
import { TransformStream } from 'stream/web';
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;
// @playwright/test 1.56+ uses TransformStream internally; jsdom doesn't expose it
// but it's available natively in Node 18+
Object.defineProperty(globalThis, 'TransformStream', {
value: TransformStream,
writable: true,
configurable: true,
});
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);
};
});