forked from snowplow/snowplow-javascript-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpingInterval.test.ts
More file actions
71 lines (55 loc) · 1.47 KB
/
Copy pathpingInterval.test.ts
File metadata and controls
71 lines (55 loc) · 1.47 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
import { MediaPingInterval } from '../src/pingInterval';
describe('PingInterval', () => {
beforeAll(() => {
jest.useFakeTimers();
});
afterAll(() => {
jest.clearAllTimers();
});
it('should fire every 30 seconds', () => {
let pings = 0;
new MediaPingInterval(undefined, undefined, () => pings++);
for (let i = 0; i < 60; i++) {
jest.advanceTimersByTime(1000);
}
expect(pings).toBe(2);
});
it('should fire in a custom interval', () => {
let pings = 0;
new MediaPingInterval(5, undefined, () => pings++);
for (let i = 0; i < 20; i++) {
jest.advanceTimersByTime(1000);
}
expect(pings).toBe(4);
});
it('should stop firing after clear', () => {
let pings = 0;
const interval = new MediaPingInterval(undefined, undefined, () => pings++);
for (let i = 0; i < 30; i++) {
jest.advanceTimersByTime(1000);
}
interval.clear();
for (let i = 0; i < 10; i++) {
jest.advanceTimersByTime(1000);
}
expect(pings).toBe(1);
});
it('should stop firing ping events when paused', () => {
let pings = 0;
const interval = new MediaPingInterval(1, 3, () => pings++);
interval.update({
currentTime: 0,
ended: false,
loop: false,
livestream: false,
muted: false,
paused: true,
playbackRate: 1,
volume: 100,
});
for (let i = 0; i < 30; i++) {
jest.advanceTimersByTime(1000);
}
expect(pings).toBe(3);
});
});