@@ -575,9 +575,10 @@ describeWithMountingMethods('options.slots', mountingMethod => {
575
575
mountingMethod . name === 'renderToString' ,
576
576
'sets a component which can access the parent component and the child component' ,
577
577
( ) => {
578
+ const childComponentName = 'component-with-parent-name'
578
579
const localVue = createLocalVue ( )
579
580
localVue . prototype . bar = 'FOO'
580
- const ParentComponent = mount (
581
+ let ParentComponent = mount (
581
582
{
582
583
name : 'parentComponent' ,
583
584
template : '<div><slot /></div>' ,
@@ -600,11 +601,37 @@ describeWithMountingMethods('options.slots', mountingMethod => {
600
601
localVue
601
602
}
602
603
)
603
- const childComponentName = 'component-with-parent-name'
604
604
expect ( ParentComponent . vm . childComponentName ) . to . equal ( childComponentName )
605
605
expect ( ParentComponent . vm . $children . length ) . to . equal ( 2 )
606
606
expect ( ParentComponent . vm . $children . every ( c => c . $options . name === childComponentName ) ) . to . equal ( true )
607
607
expect ( ParentComponent . html ( ) ) . to . equal ( '<div><div><span baz="qux">FOO,quux</span></div><div><span baz="qux">FOO,quux</span></div></div>' )
608
+
609
+ ParentComponent = mount (
610
+ {
611
+ name : 'parentComponent' ,
612
+ template : '<div><slot /></div>' ,
613
+ data ( ) {
614
+ return {
615
+ childComponentName : ''
616
+ }
617
+ }
618
+ } ,
619
+ {
620
+ slots : {
621
+ default : {
622
+ name : childComponentName ,
623
+ template : '<p>1234</p>' ,
624
+ mounted ( ) {
625
+ this . $parent . childComponentName = this . $options . name
626
+ }
627
+ }
628
+ }
629
+ }
630
+ )
631
+ expect ( ParentComponent . vm . childComponentName ) . to . equal ( childComponentName )
632
+ expect ( ParentComponent . vm . $children . length ) . to . equal ( 1 )
633
+ expect ( ParentComponent . vm . $children . every ( c => c . $options . name === childComponentName ) ) . to . equal ( true )
634
+ expect ( ParentComponent . html ( ) ) . to . equal ( '<div><p>1234</p></div>' )
608
635
}
609
636
)
610
637
} )
0 commit comments