@@ -11,6 +11,8 @@ import {fromMarkdown} from 'mdast-util-from-markdown'
1111import { toMarkdown } from 'mdast-util-to-markdown'
1212import { headingRange } from 'mdast-util-heading-range'
1313
14+ // To do: remove casts when `from-markdown` is released.
15+
1416test ( 'headingRange' , async function ( t ) {
1517 await t . test ( 'should expose the public api' , async function ( ) {
1618 assert . deepEqual (
@@ -157,13 +159,16 @@ test('headingRange', async function (t) {
157159 await t . test (
158160 'should not remove anything when `null` is given' ,
159161 async function ( ) {
160- const tree = fromMarkdown ( [ 'Foo' , '' , '## Foo' , '' , 'Bar' , '' ] . join ( '\n' ) )
162+ const tree = /** @type {Root } */ (
163+ fromMarkdown ( [ 'Foo' , '' , '## Foo' , '' , 'Bar' , '' ] . join ( '\n' ) )
164+ )
161165
162166 headingRange ( tree , 'foo' , function ( ) {
163167 return null
164168 } )
165169
166170 assert . equal (
171+ // @ts -expect-error: remove when `to-markdown` is released.
167172 toMarkdown ( tree ) ,
168173 [ 'Foo' , '' , '## Foo' , '' , 'Bar' , '' ] . join ( '\n' )
169174 )
@@ -173,35 +178,46 @@ test('headingRange', async function (t) {
173178 await t . test (
174179 'should replace all previous nodes otherwise' ,
175180 async function ( ) {
176- const tree = fromMarkdown ( [ 'Foo' , '' , '## Foo' , '' , 'Bar' , '' ] . join ( '\n' ) )
181+ const tree = /** @type {Root } */ (
182+ fromMarkdown ( [ 'Foo' , '' , '## Foo' , '' , 'Bar' , '' ] . join ( '\n' ) )
183+ )
177184
178185 headingRange ( tree , 'foo' , function ( ) {
179186 return [ ]
180187 } )
181188
182- assert . equal ( toMarkdown ( tree ) , [ 'Foo' , '' ] . join ( '\n' ) )
189+ assert . equal (
190+ // @ts -expect-error: remove when `to-markdown` is released.
191+ toMarkdown ( tree ) ,
192+ [ 'Foo' , '' ] . join ( '\n' )
193+ )
183194 }
184195 )
185196
186197 await t . test ( 'should insert all returned nodes' , async function ( ) {
187- const tree = fromMarkdown (
188- [ 'Foo' , '' , '## Foo' , '' , 'Bar' , '' , '## Baz' , '' ] . join ( '\n' )
198+ const tree = /** @type {Root } */ (
199+ fromMarkdown (
200+ [ 'Foo' , '' , '## Foo' , '' , 'Bar' , '' , '## Baz' , '' ] . join ( '\n' )
201+ )
189202 )
190203
191204 headingRange ( tree , 'foo' , function ( start , _ , end ) {
192205 return [ start , { type : 'thematicBreak' } , end ]
193206 } )
194207
195208 assert . equal (
209+ // @ts -expect-error: remove when `to-markdown` is released.
196210 toMarkdown ( tree ) ,
197211 [ 'Foo' , '' , '## Foo' , '' , '***' , '' , '## Baz' , '' ] . join ( '\n' )
198212 )
199213 } )
200214
201215 await t . test ( 'should not insert an empty `end`' , async function ( ) {
202- const tree = fromMarkdown (
203- [ '# Alpha' , '' , '## Foo' , '' , 'one' , '' , 'two' , '' , 'three' , '' ] . join (
204- '\n'
216+ const tree = /** @type {Root } */ (
217+ fromMarkdown (
218+ [ '# Alpha' , '' , '## Foo' , '' , 'one' , '' , 'two' , '' , 'three' , '' ] . join (
219+ '\n'
220+ )
205221 )
206222 )
207223
@@ -211,6 +227,7 @@ test('headingRange', async function (t) {
211227 } )
212228
213229 assert . equal (
230+ // @ts -expect-error: remove when `to-markdown` is released.
214231 toMarkdown ( tree ) ,
215232 [ '# Alpha' , '' , '## Foo' , '' , 'one' , '' , 'two' , '' , 'three' , '' ] . join (
216233 '\n'
@@ -335,7 +352,7 @@ test('headingRange', async function (t) {
335352 * Output markdown.
336353 */
337354function checkAndRemove ( value , options ) {
338- const tree = fromMarkdown ( value )
355+ const tree = /** @type { Root } */ ( fromMarkdown ( value ) )
339356
340357 headingRange ( tree , options , function ( start , _ , end , scope ) {
341358 assert . equal ( typeof scope . start , 'number' )
@@ -344,5 +361,6 @@ function checkAndRemove(value, options) {
344361 return [ start , end ]
345362 } )
346363
364+ // @ts -expect-error: remove when `to-markdown` is released.
347365 return toMarkdown ( tree )
348366}
0 commit comments