/
test.js
80 lines (69 loc) · 1.67 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* @typedef {import('./index.js').Options} Options
* @typedef {import('virtual-dom').VNode} VNode
*/
import test from 'tape'
import {remark} from 'remark'
import {h} from 'virtual-dom'
// @ts-expect-error: untyped.
import vdom2html from 'vdom-to-html'
import vdom from './index.js'
test('remark-vdom', (t) => {
/**
* @param {string} [fixture]
* @param {Options} [options]
*/
function check(fixture, options) {
return vdom2html(remark().use(vdom, options).processSync(fixture).result)
}
t.equal(
check(),
'<div></div>',
'should return an empty `div` without content'
)
t.equal(
check('_Emphasis_, **importance**, and `code`.'),
'<div><p><em>Emphasis</em>, <strong>importance</strong>, and <code>code</code>.</p></div>',
'should compile content'
)
t.equal(
check('_Emphasis_!', {
// @ts-expect-error: TS tripping up, it’s fine.
h(name, props, children) {
return h(name === 'EM' ? 'I' : name, props, children)
}
}),
'<div><p><i>Emphasis</i>!</p></div>',
'`h`'
)
t.equal(
check('_Emphasis_!', {
sanitize: {tagNames: []}
}),
'<div>Emphasis!</div>',
'`sanitize`'
)
t.equal(
check('_Emphasis_!', {
sanitize: false
}),
'<div><p><em>Emphasis</em>!</p></div>',
'`sanitize: false`'
)
t.equal(
check('_Emphasis_!', {
components: {
em(_, _1, children) {
return children
}
}
}),
'<div><p>Emphasis!</p></div>',
'`components`'
)
const node = /** @type {VNode} */ (
remark().use(vdom, {prefix: 'f-'}).processSync('_Emphasis_!').result
)
t.equal(node.key, 'f-1', '`prefix`')
t.end()
})