@@ -359,7 +359,7 @@ describe('slot-controller', () => {
359359 expect ( children [ 0 ] ) . to . be . instanceOf ( HTMLButtonElement ) ;
360360 } ) ;
361361
362- it ( 'should replace an element when new elements added to the slot' , async ( ) => {
362+ it ( 'should remove default node when new elements added to the slot' , async ( ) => {
363363 const defaultNode = children [ 0 ] ;
364364
365365 const foo = document . createElement ( 'div' ) ;
@@ -375,6 +375,20 @@ describe('slot-controller', () => {
375375 expect ( slotChildren [ 1 ] ) . to . equal ( bar ) ;
376376 expect ( defaultNode . isConnected ) . to . be . false ;
377377 } ) ;
378+
379+ it ( 'should store a reference to the default node in nodes array' , ( ) => {
380+ const nodes = controller . nodes ;
381+ expect ( nodes ) . to . be . instanceOf ( Array ) ;
382+ expect ( nodes . length ) . to . equal ( 1 ) ;
383+ expect ( nodes [ 0 ] ) . to . equal ( controller . defaultNode ) ;
384+ } ) ;
385+
386+ it ( 'should remove default node from nodes array when adding new element' , async ( ) => {
387+ const nodes = controller . nodes ;
388+ expect ( nodes ) . to . be . instanceOf ( Array ) ;
389+ expect ( nodes . length ) . to . equal ( 1 ) ;
390+ expect ( nodes [ 0 ] ) . to . equal ( controller . defaultNode ) ;
391+ } ) ;
378392 } ) ;
379393
380394 describe ( 'custom' , ( ) => {
@@ -394,10 +408,25 @@ describe('slot-controller', () => {
394408 it ( 'should store a reference to custom slotted elements in nodes array' , ( ) => {
395409 const nodes = controller . nodes ;
396410 expect ( nodes ) . to . be . instanceOf ( Array ) ;
411+ expect ( nodes . length ) . to . equal ( 2 ) ;
397412 expect ( nodes [ 0 ] ) . to . equal ( children [ 0 ] ) ;
398413 expect ( nodes [ 1 ] ) . to . equal ( children [ 1 ] ) ;
399414 } ) ;
400415
416+ it ( 'should update references to custom slotted elements in nodes array' , async ( ) => {
417+ const newChild = document . createElement ( 'div' ) ;
418+ element . append ( newChild ) ;
419+
420+ await nextFrame ( ) ;
421+
422+ const nodes = controller . nodes ;
423+ expect ( nodes ) . to . be . instanceOf ( Array ) ;
424+ expect ( nodes . length ) . to . equal ( 3 ) ;
425+ expect ( nodes [ 0 ] ) . to . equal ( children [ 0 ] ) ;
426+ expect ( nodes [ 1 ] ) . to . equal ( children [ 1 ] ) ;
427+ expect ( nodes [ 2 ] ) . to . equal ( newChild ) ;
428+ } ) ;
429+
401430 it ( 'should get a reference to list of elements passed to un-named slot' , ( ) => {
402431 const slotChildren = controller . getSlotChildren ( ) ;
403432 expect ( slotChildren [ 0 ] ) . to . equal ( children [ 0 ] ) ;
@@ -409,6 +438,14 @@ describe('slot-controller', () => {
409438 expect ( initializeSpy . firstCall . args [ 0 ] ) . to . equal ( children [ 0 ] ) ;
410439 expect ( initializeSpy . secondCall . args [ 0 ] ) . to . equal ( children [ 1 ] ) ;
411440 } ) ;
441+
442+ it ( 'should not remove custom elements when adding another custom element' , async ( ) => {
443+ const newChild = document . createElement ( 'div' ) ;
444+ element . append ( newChild ) ;
445+
446+ await nextFrame ( ) ;
447+ expect ( element . childElementCount ) . to . equal ( 3 ) ;
448+ } ) ;
412449 } ) ;
413450 } ) ;
414451} ) ;
0 commit comments