-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathtest.js
58 lines (56 loc) · 1.74 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
var assert = require('chai').assert;
var createDownloadLink = require('./index.js');
describe('When you invoke create-download-link,', function() {
before(function() {
var opt = {
data: 'nice data',
title: 'nice title',
filename: 'filename.txt'
};
this.anchor = createDownloadLink(opt);
});
describe('the link', function() {
it('should be of type anchor', function() {
assert.equal(this.anchor.nodeName, 'A');
});
it('should have the correct attributes', function() {
assert.equal(this.anchor.getAttribute('href'),
'data:application/octet-stream,nice%20data');
assert.equal(this.anchor.getAttribute('download'),
'filename.txt');
});
it('should have a title', function() {
assert.equal(this.anchor.childNodes.length, 1);
assert.equal(this.anchor.firstChild.nodeValue, 'nice title');
});
});
describe('creation', function() {
it('should fail if data is missing', function() {
var opt = {
title: 'nice title',
filename: 'filename.txt'
};
assert.throw(function() {
createDownloadLink(opt);
}, Error, 'No data provided to create-download-link');
});
it('should fail if title is missing', function() {
var opt = {
data: 'nice data',
filename: 'filename.txt'
};
assert.throw(function() {
createDownloadLink(opt);
}, Error, 'No title provided to create-download-link');
});
it('should fail if filename is missing', function() {
var opt = {
data: 'nice data',
title: 'nice title'
};
assert.throw(function() {
createDownloadLink(opt);
}, Error, 'No filename provided to create-download-link');
});
});
});