This repository has been archived by the owner on Sep 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
66 lines (52 loc) · 1.77 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
59
60
61
62
63
64
65
66
const { JSDOM } = require('jsdom')
const { describe, it } = require('kocha')
const assert = require('assert')
const genel = require('./')
const tags = require('html-tags')
const window = new JSDOM().window
global.document = window.document
describe('genel', () => {
it('generates the tagged template literal tag function from the given tag name', () => {
const el = genel('x-tag')`abc`
assert(el instanceof window.HTMLElement)
assert(el.tagName.toLowerCase() === 'x-tag')
assert(el.innerHTML === 'abc')
})
it('returns the first child of inner html contents if called as tag function', () => {
const el = genel`
<div>hello</div><p>world</p>
`
assert(el instanceof window.HTMLElement)
assert(el.tagName.toLowerCase() === 'div')
assert(el.innerHTML === 'hello')
})
describe('genel.<tagName>', () => {
it('exists if and only if <tagName> is a standard tag', () => {
tags.forEach(tag => {
assert(typeof genel[tag] === 'function')
})
Object.keys(genel).forEach(tag => {
assert(tags.includes(tag))
})
})
it('generates a dom element of <tagName> and the given contents', () => {
tags.forEach(tag => {
const el = genel[tag]`abc`
if (tag === 'colgroup' || tag === 'html') { // These tags seem unable to contain `abc` as innerHTML
return
}
assert(el instanceof window.HTMLElement)
assert(el.tagName.toLowerCase() === tag)
assert(el.innerHTML === 'abc')
})
})
it('handles ${} correctly', () => {
const el = genel.div`abc${1}def${'ghi'}jkl`
assert(el.innerHTML === 'abc1defghijkl')
})
it('trims innerHTML', () => {
const el = genel.div` abc `
assert(el.innerHTML === 'abc')
})
})
})