@@ -434,26 +434,52 @@ describe("core.dom tests", () => {
434
434
435
435
describe ( "create_from_string" , ( ) => {
436
436
it ( "Creates a DOM element from a string" , ( done ) => {
437
- let res = dom . create_from_string ( `
437
+ const res = dom . create_from_string ( `
438
438
<section id="section1">
439
439
<span class='yo'>does work.</span>
440
440
</section>` ) ;
441
441
442
- expect ( res . getAttribute ( "id" ) ) . toEqual ( "section1" ) ;
443
- expect ( res . querySelector ( "span.yo" ) . textContent ) . toEqual ( "does work." ) ;
442
+ // The returned result is like a NodeList
443
+ expect ( res . firstChild . getAttribute ( "id" ) ) . toEqual ( "section1" ) ;
444
+ expect ( res . firstChild . querySelector ( "span.yo" ) . textContent ) . toEqual (
445
+ "does work."
446
+ ) ;
447
+
448
+ done ( ) ;
449
+ } ) ;
444
450
445
- res = dom . create_from_string ( `
451
+ it ( "Creates multiple siblings from a string" , ( done ) => {
452
+ const res = dom . create_from_string ( `
446
453
<section id="section1"></section>
447
454
<section id="section2"></section>
448
455
` ) ;
449
- // Section 2 is not returned.
450
- expect ( res . getAttribute ( "id" ) ) . toEqual ( "section1" ) ;
456
+ // Multiple sibplings are also returned.
457
+ const sections = res . querySelectorAll ( "section" ) ;
458
+ expect ( sections [ 0 ] . getAttribute ( "id" ) ) . toEqual ( "section1" ) ;
459
+ expect ( sections [ 1 ] . getAttribute ( "id" ) ) . toEqual ( "section2" ) ;
460
+
461
+ done ( ) ;
462
+ } ) ;
463
+
464
+ it ( "Can append multiple siblings to another DOM node" , ( done ) => {
465
+ const res = dom . create_from_string ( `
466
+ <section id="section1"></section>
467
+ <section id="section2"></section>
468
+ ` ) ;
469
+ const el = document . createElement ( "div" ) ;
470
+ // Multiple siblings can be appended to another element
471
+ el . append ( res ) ;
472
+ expect ( el . querySelectorAll ( "section" ) . length ) . toBe ( 2 ) ;
473
+
474
+ done ( ) ;
475
+ } ) ;
451
476
452
- // TD elements or others which can not be direct children of a
453
- // <div> are not yet supported.
477
+ it ( "It cannot create out-of-context elements like a <td> without a <table> 😔" , ( done ) => {
478
+ // TD elements or others which need to be defined in the context of a <table>
479
+ // are not yet supported.
454
480
// Also see: https://stackoverflow.com/a/494348/1337474
455
- res = dom . create_from_string ( `<td></td>` ) ;
456
- expect ( res ) . toBeFalsy ( ) ;
481
+ const res = dom . create_from_string ( `<td></td>` ) ;
482
+ expect ( res . firstChild ) . toBe ( null ) ;
457
483
458
484
done ( ) ;
459
485
} ) ;
0 commit comments