@@ -638,6 +638,112 @@ moduleFor(
638638 assertHTML ( '' ) ;
639639 }
640640
641+ '@test multiple calls to render in to the same element appear as siblings' ( ) {
642+ let aHelper = ( str : string ) => str . toUpperCase ( ) ;
643+ let Child = defComponent ( `Hi: {{aHelper "there"}}` , { scope : { aHelper } } ) ;
644+ let get = ( id : string ) => this . element . querySelector ( id ) ;
645+ function render ( Comp : GlimmerishComponent , id : string , owner : Owner ) {
646+ renderComponent ( Comp , {
647+ into : get ( `#${ id } ` ) ! ,
648+ owner,
649+ } ) ;
650+ }
651+ let A = defComponent ( 'a:<Child />' , { scope : { Child } } ) ;
652+ let Root = defComponent (
653+ [
654+ `<div id="a"></div><br>` ,
655+ // both of these go in the div
656+ `{{render A 'a' owner}}` ,
657+ `{{render A 'a'}}` ,
658+ ] . join ( '\n' ) ,
659+ { scope : { render, A, owner : this . owner } }
660+ ) ;
661+
662+ this . renderComponent ( Root , {
663+ expect : [ `<div id="a">a:Hi: THEREa:Hi: THERE</div><br>` , '' , '' ] . join ( '\n' ) ,
664+ } ) ;
665+ run ( ( ) => destroy ( this ) ) ;
666+
667+ assertHTML ( '' ) ;
668+ }
669+
670+ /**
671+ * NOTE: subsequent renders to the same element are prepended to the element's children
672+ */
673+ '@test multiple calls to render in to the same element appear as siblings and can be updated' ( ) {
674+ let aHelper = ( str : string ) => str . toUpperCase ( ) ;
675+ let dataA = trackedObject ( { count : 1 } ) ;
676+ let dataB = trackedObject ( { count : - 1 } ) ;
677+ let Child = defComponent ( `Hi: {{aHelper "there"}}` , { scope : { aHelper } } ) ;
678+
679+ let get = ( id : string ) => this . element . querySelector ( id ) ;
680+ function render ( Comp : GlimmerishComponent , id : string , owner : Owner ) {
681+ renderComponent ( Comp , {
682+ into : get ( `#${ id } ` ) ! ,
683+ owner,
684+ } ) ;
685+ }
686+ let A = defComponent ( '\n<output>a:<Child />:{{data.count}}</output>\n' , {
687+ scope : { Child, data : dataA } ,
688+ } ) ;
689+ let B = defComponent ( '\n<output>b:<Child />:{{data.count}}</output>' , {
690+ scope : { Child, data : dataB } ,
691+ } ) ;
692+
693+ let Root = defComponent (
694+ [
695+ `<div id="a"></div><br>` ,
696+ // both of these go in the div
697+ `{{render A 'a' owner}}` ,
698+ `{{render B 'a'}}` ,
699+ ] . join ( '\n' ) ,
700+ { scope : { render, A, B, owner : this . owner } }
701+ ) ;
702+
703+ this . renderComponent ( Root , {
704+ expect : [
705+ `<div id="a">` ,
706+ `<output>b:Hi: THERE:-1</output>` ,
707+ `<output>a:Hi: THERE:1</output>` ,
708+ `</div><br>` ,
709+ '' ,
710+ '' ,
711+ ] . join ( '\n' ) ,
712+ } ) ;
713+
714+ this . assertChange ( {
715+ change : ( ) => dataA . count ++ ,
716+ expect : [
717+ `<div id="a">` ,
718+ `<output>b:Hi: THERE:-1</output>` ,
719+ `<output>a:Hi: THERE:2</output>` ,
720+ `</div><br>` ,
721+ '' ,
722+ '' ,
723+ ] . join ( '\n' ) ,
724+ } ) ;
725+
726+ /**
727+ * ERROR in conflict with the NOTE on this test.
728+ * the elementns flip locations... which is kinda bonkers
729+ */
730+ this . assertChange ( {
731+ change : ( ) => dataB . count -- ,
732+ expect : [
733+ `<div id="a">` ,
734+ `<output>b:Hi: THERE:-2</output>` ,
735+ `<output>a:Hi: THERE:2</output>` ,
736+ `</div><br>` ,
737+ '' ,
738+ '' ,
739+ ] . join ( '\n' ) ,
740+ } ) ;
741+
742+ run ( ( ) => destroy ( this ) ) ;
743+
744+ assertHTML ( '' ) ;
745+ }
746+
641747 async '@test async rendering multiple times to adjacent elements' ( ) {
642748 let Child = defComponent ( `Hi` , { scope : { } } ) ;
643749 let get = ( id : string ) => this . element . querySelector ( id ) ;
0 commit comments