-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
53 lines (41 loc) · 1.25 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
/* istanbul ignore next */
describe('beacons', function () {
'use strict';
//
// Polyfill for missing browser global, should be loaded before requiring the
// modules.
//
global.Image = require('./image');
var assume = require('assume')
, beacon = require('./');
it('is exported as function', function () {
assume(beacon).is.a('function');
});
it('returns a constructed Image instance', function () {
var img = beacon('url', function () {});
assume(img).is.instanceOf(Image);
assume(img.src).equals('url');
});
it('calls the callback after the specified timeout', function (next) {
var start = Date.now();
beacon('url', function (e) {
var spend = Date.now() - start;
assume(spend).is.below(110);
assume(spend).is.above(95);
assume(e).is.instanceof(Error);
next();
}, 100);
});
it('it calls the callback when an error load is triggered', function (next) {
var img = beacon('url', next);
img.emit('error');
});
it('it calls the callback when an load event is triggered', function (next) {
var img = beacon('url', next);
img.emit('load');
});
it('can be called without a function', function () {
var img = beacon('url');
img.emit('load');
});
});