/
test-tag.js
53 lines (46 loc) · 1.37 KB
/
test-tag.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
/*jslint node: true */
'use strict';
var test = require('tape');
var tag = require('../lib/tag');
var forms = require('../');
test('generates a self-closing tag', function (t) {
var attrs = {
classes: ['foo', 'bar'],
src: 'foo.jpg'
};
var html = tag('img', attrs, 'self-closing tags have no content');
t.equal(html, '<img src="foo.jpg" class="foo bar" />');
t.end();
});
test('generates a non-self-closing tag', function (t) {
var attrs = {
classes: ['foo', 'bar'],
'data-foo': 'baz'
};
var html = tag('div', attrs, 'some content');
t.equal(html, '<div data-foo="baz" class="foo bar">some content</div>');
t.end();
});
test('allow empty attributes', function (t) {
var html = forms.widgets.select().toHTML('field', {
choices: {
'': 'Make a choice',
choice1: 'Choice 1',
choice2: 'Choice 2'
}
});
t.equal(html,
'<select name="field" id="id_field">' +
'<option value="">Make a choice</option>' +
'<option value="choice1">Choice 1</option>' +
'<option value="choice2">Choice 2</option>' +
'</select>'
);
var html = forms.widgets.text({
'data-empty': ''
}).toHTML('field');
t.equal(html,
'<input type="text" name="field" id="id_field" data-empty="" />'
);
t.end();
});