-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main-tests.js
77 lines (63 loc) · 1.57 KB
/
main-tests.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
69
70
71
72
73
74
75
76
77
const { throws, deepEqual } = require('assert');
const mod = require('./main.js');
describe('_fetch', function test__fetch() {
const __fetch = function (inputData = {}) {
return mod._fetch(inputData.url || uLink(), Object.assign({
fetch: (function () {
if (inputData._fetch) {
inputData._fetch(...arguments);
}
return {
response: 200,
text: (function () {
return inputData.text || {};
}),
};
}),
}));
};
it('calls window.fetch', async function () {
const url = uLink();
deepEqual(await uCapture(function (_fetch) {
return __fetch({
url,
_fetch,
});
}), [mod._corsProxy() + url]);
});
it('returns response.text', async function () {
const text = Math.random().toString();
deepEqual(await __fetch({
text,
}), text);
});
});
describe('DOMContentLoaded', function test_DOMContentLoaded() {
const _DOMContentLoaded = function (inputData = {}) {
return Object.assign(Object.assign({}, mod), {
populate: (function () {}),
}, inputData).DOMContentLoaded();
};
it.skip('calls populate', async function () {
const item = Math.random().toString();
deepEqual(await uCapture(function (populate) {
_DOMContentLoaded({
async goLoad () {
return item;
},
populate,
});
}), [item]);
});
});
describe('lifeDidLoad', function test_lifeDidLoad() {
it.skip('listens for DOMContentLoaded', function () {
deepEqual(uCapture(function (addEventListener) {
mod.lifeDidLoad({
document: {
addEventListener,
},
});
}), ['DOMContentLoaded', mod.DOMContentLoaded]);
});
});