-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
45 lines (38 loc) · 861 Bytes
/
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
var loaded = require('./')
, test = require('tape')
, src = 'https://raw.github.com/hughsk/image-loaded/master/test.png'
test('Image loaded already', function(t) {
var image = new Image
t.plan(2)
image.onload = function() {
loaded(image, function(err, already) {
t.error(err)
t.ok(already)
})
}
image.src = src
})
test('Image loaded afterwards', function(t) {
var image = new Image
t.plan(2)
loaded(image, function(err, already) {
t.error(err)
t.ok(!already)
})
setTimeout(function() {
image.src = src
}, 500)
})
test('Pass an error with the wrong element', function(t) {
var div = document.createElement('div')
t.plan(1)
loaded(div, function(err) {
t.ok(err)
})
})
test('Pass an error with a non-element', function(t) {
t.plan(1)
loaded({}, function(err) {
t.ok(err)
})
})