forked from marmelab/react-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-setup.js
65 lines (60 loc) · 1.59 KB
/
test-setup.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
require('raf/polyfill');
/**
* As jsDom do not support mutationobserver and
* quill requires mutationobserver, thus a shim is needed
*/
require('mutationobserver-shim');
/**
* Mock PopperJS
*
* When using mount(), material-ui calls Popper.js, which is not compatible with JSDom
* And causes UnhandledPromiseRejectionWarning: TypeError: document.createRange is not a function
*
* @see https://github.com/FezVrasta/popper.js/issues/478
*/
jest.mock('popper.js', () => {
class Popper {
constructor() {
return {
destroy: () => {},
scheduleUpdate: () => {},
update: () => {},
};
}
}
Popper.placements = [
'auto',
'auto-end',
'auto-start',
'bottom',
'bottom-end',
'bottom-start',
'left',
'left-end',
'left-start',
'right',
'right-end',
'right-start',
'top',
'top-end',
'top-start',
];
return Popper;
});
// Ignore warnings about act()
// See https://github.com/testing-library/react-testing-library/issues/281,
// https://github.com/facebook/react/issues/14769
const originalError = console.error;
jest.spyOn(console, 'error').mockImplementation((...args) => {
if (/Warning.*not wrapped in act/.test(args[0])) {
return;
}
originalError.call(console, ...args);
});
/**
* Mock fetch objects Response, Request and Headers
*/
const { Response, Headers, Request } = require('whatwg-fetch');
global.Response = Response;
global.Headers = Headers;
global.Request = Request;