forked from kitajs/html
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.test.ts
92 lines (80 loc) · 2.21 KB
/
util.test.ts
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import assert from 'assert'
import { describe, test } from 'node:test'
import { Html } from '../index'
describe('Util', () => {
test('Undefined contents', async () => {
assert.equal(
await Html.contentsToString([
undefined,
Promise.resolve(undefined),
[undefined, Promise.resolve(undefined)],
null,
Promise.resolve(null),
[null, Promise.resolve(null)],
[[[[[[[]]]]]]]
]),
''
)
assert.equal(await Html.contentsToString([]), '')
})
test('Deep scaping', async () => {
assert.equal(
await Html.contentsToString(['<>', Promise.resolve('<>')], true),
'<><>'
)
assert.equal(
await Html.contentsToString(
[
undefined,
Promise.resolve(undefined),
[undefined, Promise.resolve(undefined)],
null,
Promise.resolve(null),
[null, Promise.resolve(null)],
[[[[[[['<>']]]]]]]
],
true
),
'<>'
)
})
test('String contents', async () => {
assert.equal(
await Html.contentsToString([
'a',
Promise.resolve('b'),
['c', Promise.resolve('d')]
]),
'abcd'
)
})
test('Only string contents', async () => {
assert.equal(await Html.contentsToString(['a', 'b', ['c', 'd']]), 'abcd')
})
test('Promises', async () => {
const result = Html.contentsToString([
Promise.resolve('a'),
Promise.resolve('b'),
Promise.resolve(['c', Promise.resolve('d')])
])
assert.ok(result instanceof Promise)
assert.equal(await result, 'abcd')
})
test('h() function', async () => {
assert.equal(Html.h, Html.createElement)
})
test('esm and cjs usage', async () => {
const Html0 = require('../index')
const { Html: Html1 } = require('../index')
const Html2 = require('../index').default
const Html3 = await import('../index')
const { Html: Html4 } = await import('../index')
const Html5 = (await import('../index')).default
assert.deepEqual(Html0, Html)
assert.deepEqual(Html1, Html)
assert.deepEqual(Html2, Html)
assert.deepEqual(Html3, Html)
assert.deepEqual(Html4, Html)
assert.deepEqual(Html5, Html)
})
})