-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
49 lines (37 loc) · 1.08 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
var test = require("prova");
var img = require('./');
var logo = 'https://avatars2.githubusercontent.com/u/7551498';
var gif = 'http://azer.bike/cat1.gif';
var baboon = require('baboon-image-uri');
test('returns an image element', function (t) {
t.plan(2);
var el = img(logo);
document.documentElement.appendChild(el);
var _el = document.querySelector('img');
t.ok(_el);
t.equal(_el.src, logo);
el.parentNode.removeChild(el);
});
test('runs the callback when the img is loaded', function (t) {
t.plan(4);
img(gif, function (error, el) {
t.error(error);
t.notOk(document.querySelector('img'));
document.documentElement.appendChild(el);
var _el = document.querySelector('img');
t.ok(_el);
t.equal(_el.src, gif);
el.parentNode.removeChild(el);
});
});
test('allows crossOrigin options', function (t) {
var result = img(baboon, { crossOrigin: 'Anonymous' });
t.equal(result.crossOrigin.toLowerCase(), 'anonymous');
t.end();
});
test('fails to load', function (t) {
t.plan(1);
img('doesnt exist', function (error) {
t.ok(error);
});
});