-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.js
62 lines (49 loc) · 1.24 KB
/
test.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
import test from 'ava';
import mock from 'xhr-mock';
import noInternet from './src/no-internet';
import SetInterval from 'set-interval';
import browserEnv from 'browser-env';
browserEnv(['window', 'document', 'navigator', 'XMLHttpRequest']);
const URL = 'https://www.google.com/favicon.ico';
test.before(t => {
mock.setup();
mock.get(URL, function (req, res) {
return res.status(200)
});
});
test('module should be a function', t => {
t.is(typeof noInternet, 'function');
});
// TODO: check Travis configuration for HTTP request
// test('one check', t => {
// return noInternet({ url: URL }).then(offline => {
// t.false(offline);
// });
// });
test.cb('interval checking', t => {
const options = {
url: URL,
callback: noInternetCallback,
headers: { 'Access-Control-Allow-Origin': '*' }
};
noInternet(options);
function noInternetCallback(offline) {
t.false(offline);
}
setTimeout(t.end);
});
test.cb('should clear interval checking', t => {
const options = {
url: URL,
callback: () => { }
};
noInternet(options);
noInternet.clearInterval();
t.is(SetInterval.key['checkConnection'], void 0);
setTimeout(t.end);
});
test('invalid URL', t => {
return noInternet().then(offline => {
t.true(offline);
});
});