@@ -28,15 +28,15 @@ test('hast-to-hyperscript', function (t) {
28
28
t . test ( 'should throw if not given a node' , function ( st ) {
29
29
t . throws ( function ( ) {
30
30
toH ( h ) ;
31
- } , / E x p e c t e d e l e m e n t , n o t ` u n d e f i n e d ` / ) ;
31
+ } , / E x p e c t e d r o o t o r e l e m e n t , n o t ` u n d e f i n e d ` / ) ;
32
32
33
33
t . throws ( function ( ) {
34
- toH ( h , 'text' ) ;
35
- } , / E r r o r : E x p e c t e d e l e m e n t , n o t ` t e x t ` / ) ;
34
+ toH ( h , u ( 'text' , 'Alpha' ) ) ;
35
+ } , / E r r o r : E x p e c t e d r o o t o r e l e m e n t , n o t ` t e x t ` / ) ;
36
36
37
37
t . throws ( function ( ) {
38
38
toH ( h , u ( 'text' , 'value' ) ) ;
39
- } , / E x p e c t e d e l e m e n t / ) ;
39
+ } , / E x p e c t e d r o o t o r e l e m e n t / ) ;
40
40
41
41
st . end ( ) ;
42
42
} ) ;
@@ -274,6 +274,49 @@ test('hast-to-hyperscript', function (t) {
274
274
st . end ( ) ;
275
275
} ) ;
276
276
277
+ t . test ( 'flattens a `root` with one element child to that child' , function ( st ) {
278
+ var actual = toH ( h , u ( 'root' , [ u ( 'element' , { tagName : 'h1' , properties : { id : 'a' } } , [ ] ) ] ) ) ;
279
+ var expected = h ( 'h1#a' ) ;
280
+ var doc = '<h1 id="a"></h1>' ;
281
+
282
+ st . deepEqual ( html ( actual . outerHTML ) , html ( doc ) , 'equal output' ) ;
283
+ st . deepEqual ( html ( expected . outerHTML ) , html ( doc ) , 'equal output baseline' ) ;
284
+ st . end ( ) ;
285
+ } ) ;
286
+
287
+ t . test ( 'flattens a `root` without children to a `div`' , function ( st ) {
288
+ var actual = toH ( h , u ( 'root' , [ ] ) ) ;
289
+ var expected = h ( 'div' ) ;
290
+ var doc = '<div></div>' ;
291
+
292
+ st . deepEqual ( html ( actual . outerHTML ) , html ( doc ) , 'equal output' ) ;
293
+ st . deepEqual ( html ( expected . outerHTML ) , html ( doc ) , 'equal output baseline' ) ;
294
+ st . end ( ) ;
295
+ } ) ;
296
+
297
+ t . test ( 'flattens a `root` with a text child to a `div`' , function ( st ) {
298
+ var actual = toH ( h , u ( 'root' , [ u ( 'text' , 'Alpha' ) ] ) ) ;
299
+ var expected = h ( 'div' , 'Alpha' ) ;
300
+ var doc = '<div>Alpha</div>' ;
301
+
302
+ st . deepEqual ( html ( actual . outerHTML ) , html ( doc ) , 'equal output' ) ;
303
+ st . deepEqual ( html ( expected . outerHTML ) , html ( doc ) , 'equal output baseline' ) ;
304
+ st . end ( ) ;
305
+ } ) ;
306
+
307
+ t . test ( 'flattens a `root` with more children to a `div`' , function ( st ) {
308
+ var actual = toH ( h , u ( 'root' , [
309
+ u ( 'element' , { tagName : 'h1' } , [ u ( 'text' , 'Alpha' ) ] ) ,
310
+ u ( 'element' , { tagName : 'p' } , [ u ( 'text' , 'Bravo' ) ] )
311
+ ] ) ) ;
312
+ var expected = h ( 'div' , [ h ( 'h1' , 'Alpha' ) , h ( 'p' , 'Bravo' ) ] ) ;
313
+ var doc = '<div><h1>Alpha</h1><p>Bravo</p></div>' ;
314
+
315
+ st . deepEqual ( html ( actual . outerHTML ) , html ( doc ) , 'equal output' ) ;
316
+ st . deepEqual ( html ( expected . outerHTML ) , html ( doc ) , 'equal output baseline' ) ;
317
+ st . end ( ) ;
318
+ } ) ;
319
+
277
320
t . end ( ) ;
278
321
} ) ;
279
322
0 commit comments