forked from daily-co/daily-react
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest-setup.ts
47 lines (38 loc) · 1.06 KB
/
jest-setup.ts
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
import '@testing-library/jest-dom';
class MediaStream {
tracks: MediaStreamTrack[] = [];
constructor(tracks: MediaStreamTrack[]) {
this.tracks = tracks;
}
getAudioTracks() {
return this.tracks.filter(t => t.kind === 'audio');
}
getVideoTracks() {
return this.tracks.filter(t => t.kind === 'video');
}
getTracks() {
return this.tracks;
}
}
Object.defineProperty(window, 'MediaStream', {
value: MediaStream,
});
Object.defineProperty(HTMLVideoElement.prototype, 'load', {
value: () => {},
});
/**
* Avoids "Cannot flush updates when React is already rendering." warnings in DailyVideo test output.
* Source: https://github.com/testing-library/react-testing-library/issues/470#issuecomment-710775040
*/
Object.defineProperty(HTMLMediaElement.prototype, 'muted', {
set: () => {},
});
/**
* Setting mocked values, otherwise videoWidth and videoHeight both return 0.
*/
Object.defineProperty(HTMLVideoElement.prototype, 'videoWidth', {
value: 160,
});
Object.defineProperty(HTMLVideoElement.prototype, 'videoHeight', {
value: 90,
});