1+ /**
2+ * @typedef {import('mdast').Root } Root
3+ */
4+
5+ const assert = require ( 'node:assert/strict' )
16const test = require ( 'tape' )
27const remark = require ( 'remark' )
38const find = require ( './index.js' )
49
510test ( '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' )
717
818 t . throws ( function ( ) {
19+ // @ts -expect-error: check that an error is thrown at runtime.
920 find ( )
1021 } , 'should fail without tree' )
1122
1223 t . throws ( function ( ) {
24+ // @ts -expect-error: check that an error is thrown at runtime.
1325 find ( tree )
1426 } , 'should fail without condition' )
1527
1628 t . test ( 'should find with string condition' , function ( st ) {
1729 const result = find ( tree , 'value' )
1830
19- st . equal ( result , tree . children [ 0 ] . children [ 0 ] )
31+ st . equal ( result , paragraph . children [ 0 ] )
2032
2133 st . end ( )
2234 } )
2335
2436 t . test ( 'should find with object condition' , function ( st ) {
2537 const result = find ( tree , { type : 'emphasis' } )
2638
27- st . equal ( result , tree . children [ 0 ] . children [ 1 ] )
39+ st . equal ( result , paragraph . children [ 1 ] )
2840
2941 st . end ( )
3042 } )
@@ -34,7 +46,7 @@ test('unist-find', function (t) {
3446 return node . type === 'inlineCode'
3547 } )
3648
37- st . equal ( result , tree . children [ 0 ] . children [ 5 ] )
49+ st . equal ( result , paragraph . children [ 5 ] )
3850
3951 st . end ( )
4052 } )
0 commit comments