-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathresourceTiming.spec.ts
88 lines (82 loc) · 2.01 KB
/
resourceTiming.spec.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* @jest-environment jsdom
*/
import { config } from '../src/config';
import * as log from '../src/log';
import { rt } from '../src/metrics';
import * as resourceTiming from '../src/resourceTiming';
describe('resourceTiming', () => {
let spy: jest.SpyInstance;
describe('.initResourceTiming()', () => {
beforeEach(() => {
(rt as any).value = {
css: 0,
fetch: 0,
total: 0,
};
config.isResourceTiming = true;
});
it('should dataConsumption be 0 when entries are empty', () => {
resourceTiming.initResourceTiming([]);
expect(rt.value).toEqual({
css: 0,
fetch: 0,
total: 0,
});
});
it('should float the dataConsumption result', () => {
resourceTiming.initResourceTiming([
// @ts-ignore
{
decodedBodySize: 12345678,
// @ts-ignore
initiatorType: 'css',
},
]);
expect(rt.value).toEqual({
css: 12345.678,
fetch: 0,
total: 12345.678,
});
});
it('should sum the dataConsumption result', () => {
resourceTiming.initResourceTiming([
// @ts-ignore
{
decodedBodySize: 12345678,
// @ts-ignore
initiatorType: 'css',
},
// @ts-ignore
{
decodedBodySize: 10000678,
// @ts-ignore
initiatorType: 'fetch',
},
]);
expect(rt.value).toEqual({
css: 12345.678,
fetch: 10000.678,
total: 22346.356,
});
});
it('should call logData for each performanceEntry', () => {
spy = jest.spyOn(log, 'logData');
resourceTiming.initResourceTiming([
// @ts-ignore
{
decodedBodySize: 12345678,
// @ts-ignore
initiatorType: 'css',
},
// @ts-ignore
{
decodedBodySize: 10000678,
// @ts-ignore
initiatorType: 'fetch',
},
]);
expect(spy.mock.calls.length).toEqual(2);
});
});
});