-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest.js
55 lines (45 loc) · 1.26 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
import test from 'tape'
import {toString} from './index.js'
test('toString', (t) => {
// @ts-expect-error: runtime.
t.equal(toString(), '', 'should not fail on a missing node')
t.equal(toString(null), '', 'should not fail on `null` missing node')
t.equal(toString({value: 'foo'}), 'foo', 'should not fail on nodes w/o type')
t.equal(
toString({
value: 'foo',
alt: 'bar',
title: 'baz',
children: [{value: 'qux'}]
}),
'foo',
'should prefer `value` over all others'
)
t.equal(
toString({alt: 'bar', title: 'baz', children: [{value: 'qux'}]}),
'bar',
'should prefer `alt` over all others'
)
t.equal(
toString({title: 'baz', children: [{value: 'qux'}]}),
'qux',
'should *not* prefer `title` over all others'
)
t.equal(
toString({alt: 'bar'}, {includeImageAlt: false}),
'',
'should *not* include `alt` w/ `includeImageAlt: false`'
)
t.equal(
toString({children: [{value: 'foo'}, {alt: 'bar'}, {title: 'baz'}]}),
'foobar',
'should serialize children'
)
t.equal(
toString([{value: 'foo'}, {alt: 'bar'}, {title: 'baz'}]),
'foobar',
'should serialize a list of nodes'
)
t.equal(toString({}), '', 'should produce an empty string otherwise')
t.end()
})