-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
test.js
84 lines (72 loc) · 2.14 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
81
82
83
84
import assert from 'node:assert/strict'
import test from 'node:test'
import {toString} from 'mdast-util-to-string'
test('toString', async function (t) {
await t.test('should expose the public api', async function () {
assert.deepEqual(Object.keys(await import('mdast-util-to-string')).sort(), [
'toString'
])
})
await t.test('should not fail on a missing node', async function () {
assert.equal(toString(), '')
})
await t.test('should not fail on `null` missing node', async function () {
assert.equal(toString(null), '')
})
await t.test('should not fail on nodes w/o type', async function () {
assert.equal(toString({value: 'foo'}), 'foo')
})
await t.test('should prefer `value` over all others', async function () {
assert.equal(
toString({
value: 'foo',
alt: 'bar',
title: 'baz',
children: [{value: 'qux'}]
}),
'foo'
)
})
await t.test('should prefer `alt` over all others', async function () {
assert.equal(
toString({alt: 'bar', title: 'baz', children: [{value: 'qux'}]}),
'bar'
)
})
await t.test(
'should *not* prefer `title` over all others',
async function () {
assert.equal(toString({title: 'baz', children: [{value: 'qux'}]}), 'qux')
}
)
await t.test(
'should *not* include `alt` w/ `includeImageAlt: false`',
async function () {
assert.equal(toString({alt: 'bar'}, {includeImageAlt: false}), '')
}
)
await t.test(
'should *not* include `html` w/ `includeHtml: false`',
async function () {
assert.equal(
toString({type: 'html', value: 'a'}, {includeHtml: false}),
''
)
}
)
await t.test('should serialize children', async function () {
assert.equal(
toString({children: [{value: 'foo'}, {alt: 'bar'}, {title: 'baz'}]}),
'foobar'
)
})
await t.test('should serialize a list of nodes', async function () {
assert.equal(
toString([{value: 'foo'}, {alt: 'bar'}, {title: 'baz'}]),
'foobar'
)
})
await t.test('should produce an empty string otherwise', async function () {
assert.equal(toString({}), '')
})
})