-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
72 lines (66 loc) · 1.94 KB
/
index.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { test } from 'tap';
import tag from '../src';
test('End tags must not be specified for void elements', (t) => {
const voidElements = [
'area',
'base',
'br',
'col',
'embed',
'hr',
'img',
'input',
'keygen',
'link',
'meta',
'param',
'source',
'track',
'wbr'
];
voidElements.forEach(voidElement => {
t.equal(tag(voidElement), '<' + voidElement + '>');
});
t.end();
});
test('Defaults to div if tag is not specified', (t) => {
const result = tag({
class: 'container'
}, 'container text');
const wanted = '<div class="container">container text</div>';
t.equal(result, wanted);
t.end();
});
test('Escapes special characters', (t) => {
const result = tag('div', {
class: 'container',
title: '\'"&<>'
}, tag('i', { class: 'icon' }));
const wanted = '<div class="container" title="'"&<>"><i class="icon"/></div>';
t.equal(result, wanted);
t.end();
});
test('Boolean attributes', (t) => {
t.equal(tag('input', { type: 'checkbox', disabled: true }), '<input type="checkbox" disabled>');
t.equal(tag('input', { type: 'checkbox', disabled: false, checked: true }), '<input type="checkbox" checked>');
t.end();
});
test('A tag', (t) => {
const result = tag('a', {
class: 'btn btn-link',
href: 'http://github.com/cheton/html-tag',
}, 'http://github.com/cheton/html-tag');
const wanted = '<a class="btn btn-link" href="http://github.com/cheton/html-tag">http://github.com/cheton/html-tag</a>'
t.equal(result, wanted);
t.end();
});
test('INPUT tag', (t) => {
const result = tag('input', {
name: 'name',
value: 'Input your name...',
disabled: true
});
const wanted = '<input name="name" value="Input your name..." disabled>';
t.equal(result, wanted);
t.end();
});