1
+ /**
2
+ * @typedef {import('mdast').Root } Root
3
+ */
4
+
5
+ const assert = require ( 'node:assert/strict' )
1
6
const test = require ( 'tape' )
2
7
const remark = require ( 'remark' )
3
8
const find = require ( './index.js' )
4
9
5
10
test ( 'unist-find' , function ( t ) {
6
- const tree = remark ( ) . parse ( 'Some _emphasis_, **strongness**, and `code`.' )
11
+ const tree = /** @type {Root } */ (
12
+ remark ( ) . parse ( 'Some _emphasis_, **strongness**, and `code`.' )
13
+ )
14
+ assert ( tree . type === 'root' )
15
+ const paragraph = tree . children [ 0 ]
16
+ assert ( paragraph . type === 'paragraph' )
7
17
8
18
t . throws ( function ( ) {
19
+ // @ts -expect-error: check that an error is thrown at runtime.
9
20
find ( )
10
21
} , 'should fail without tree' )
11
22
12
23
t . throws ( function ( ) {
24
+ // @ts -expect-error: check that an error is thrown at runtime.
13
25
find ( tree )
14
26
} , 'should fail without condition' )
15
27
16
28
t . test ( 'should find with string condition' , function ( st ) {
17
29
const result = find ( tree , 'value' )
18
30
19
- st . equal ( result , tree . children [ 0 ] . children [ 0 ] )
31
+ st . equal ( result , paragraph . children [ 0 ] )
20
32
21
33
st . end ( )
22
34
} )
23
35
24
36
t . test ( 'should find with object condition' , function ( st ) {
25
37
const result = find ( tree , { type : 'emphasis' } )
26
38
27
- st . equal ( result , tree . children [ 0 ] . children [ 1 ] )
39
+ st . equal ( result , paragraph . children [ 1 ] )
28
40
29
41
st . end ( )
30
42
} )
@@ -34,7 +46,7 @@ test('unist-find', function (t) {
34
46
return node . type === 'inlineCode'
35
47
} )
36
48
37
- st . equal ( result , tree . children [ 0 ] . children [ 5 ] )
49
+ st . equal ( result , paragraph . children [ 5 ] )
38
50
39
51
st . end ( )
40
52
} )
0 commit comments