-
Notifications
You must be signed in to change notification settings - Fork 16
/
jest-setup.ts
70 lines (57 loc) · 1.59 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import '@testing-library/jest-dom';
import { FakeMediaStreamTrack } from 'fake-mediastreamtrack';
import { faker } from '@faker-js/faker';
class MediaStream {
active: boolean;
id: string;
tracks: MediaStreamTrack[] = [];
constructor(tracks: MediaStreamTrack[] = [], id?: string) {
this.tracks = tracks;
this.id = id ?? faker.string.uuid();
this.active = true;
}
addTrack(track: MediaStreamTrack) {
this.tracks.push(track);
}
removeTrack(track: MediaStreamTrack) {
this.tracks = this.tracks.filter(t => t.id !== track.id);
}
getAudioTracks() {
return this.tracks.filter(t => t.kind === 'audio');
}
getVideoTracks() {
return this.tracks.filter(t => t.kind === 'video');
}
getTracks() {
return this.tracks;
}
stop() {
this.active = false;
}
}
Object.defineProperty(window, 'MediaStream', {
value: MediaStream,
});
Object.defineProperty(window, 'MediaStreamTrack', {
writable: true,
value: FakeMediaStreamTrack,
})
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,
});