-
Notifications
You must be signed in to change notification settings - Fork 138
/
Copy pathjest-setup.js
68 lines (57 loc) · 1.62 KB
/
jest-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
66
67
68
import './__mocks__/intersectionObserverMock';
import '@testing-library/jest-dom';
const { JSDOM } = require('jsdom');
// for mount
const jsdom = new JSDOM('<!doctype html><html><body></body></html>', { url: 'http://localhost' });
const { window } = jsdom;
function copyProps(src, target) {
Object.defineProperties(target, {
...Object.getOwnPropertyDescriptors(src),
...Object.getOwnPropertyDescriptors(target),
});
}
global.window = window;
global.document = window.document;
global.navigator = {
userAgent: 'node.js',
};
global.requestAnimationFrame = function (callback) {
return setTimeout(callback, 0);
};
global.cancelAnimationFrame = function (id) {
clearTimeout(id);
};
// MediaRecorder and MediaRecorder.isTypeSupported are used within SendbirdProvider's internal logic.
class MockMediaRecorder {
static isTypeSupported(type) {
const supportedMimeTypes = ['audio/webm', 'audio/wav'];
return supportedMimeTypes.includes(type);
}
constructor() {
this.state = 'inactive';
this.ondataavailable = null;
this.onerror = null;
this.onpause = null;
this.onresume = null;
this.onstart = null;
this.onstop = null;
}
start() {
this.state = 'recording';
if (this.onstart) this.onstart(new Event('start'));
}
stop() {
this.state = 'inactive';
if (this.onstop) this.onstop(new Event('stop'));
}
pause() {
this.state = 'paused';
if (this.onpause) this.onpause(new Event('pause'));
}
resume() {
this.state = 'recording';
if (this.onresume) this.onresume(new Event('resume'));
}
}
global.MediaRecorder = MockMediaRecorder;
copyProps(window, global);