@@ -2,8 +2,10 @@ import { compileToFunctions } from 'vue-template-compiler'
2
2
import Component from '~resources/components/component.vue'
3
3
import ComponentWithSlots from '~resources/components/component-with-slots.vue'
4
4
import ComponentAsAClass from '~resources/components/component-as-a-class.vue'
5
+ import ComponentWithParentName from '~resources/components/component-with-parent-name.vue'
5
6
import { describeWithMountingMethods , vueVersion } from '~resources/utils'
6
7
import { itSkipIf , itDoNotRunIf } from 'conditional-specs'
8
+ import { mount , createLocalVue } from '~vue/test-utils'
7
9
8
10
describeWithMountingMethods ( 'options.slots' , mountingMethod => {
9
11
it ( 'mounts component with default slot if passed component in slot object' , ( ) => {
@@ -224,14 +226,16 @@ describeWithMountingMethods('options.slots', mountingMethod => {
224
226
it ( 'mounts component with text slot' , ( ) => {
225
227
const wrapper = mountingMethod ( ComponentWithSlots , {
226
228
slots : {
227
- default : 'hello,' ,
228
- header : 'world'
229
+ header : 'hello,' ,
230
+ default : 'world'
229
231
}
230
232
} )
231
233
if ( mountingMethod . name === 'renderToString' ) {
232
- expect ( wrapper ) . contains ( 'hello,world' )
234
+ expect ( wrapper ) . contains ( 'hello,' )
235
+ expect ( wrapper ) . contains ( 'world' )
233
236
} else {
234
- expect ( wrapper . text ( ) ) . to . contain ( 'hello,world' )
237
+ expect ( wrapper . find ( 'header' ) . text ( ) ) . to . equal ( 'hello,' )
238
+ expect ( wrapper . find ( 'main' ) . text ( ) ) . to . equal ( 'world' )
235
239
}
236
240
} )
237
241
@@ -546,4 +550,35 @@ describeWithMountingMethods('options.slots', mountingMethod => {
546
550
wrapper . find ( 'div' ) . trigger ( 'click' )
547
551
}
548
552
)
553
+
554
+ itDoNotRunIf (
555
+ mountingMethod . name === 'renderToString' ,
556
+ 'sets a component which can access the parent component' ,
557
+ ( ) => {
558
+ const localVue = createLocalVue ( )
559
+ localVue . prototype . bar = 'FOO'
560
+ const wrapperComponent = mount (
561
+ {
562
+ name : 'parentComponent' ,
563
+ template : '<div><slot /></div>' ,
564
+ data ( ) {
565
+ return {
566
+ childName : ''
567
+ }
568
+ }
569
+ } ,
570
+ {
571
+ components : {
572
+ ComponentWithParentName
573
+ } ,
574
+ slots : {
575
+ default : '<component-with-parent-name :foo="bar" />'
576
+ } ,
577
+ localVue
578
+ }
579
+ )
580
+ expect ( wrapperComponent . vm . childName ) . to . equal ( 'component-with-parent-name' )
581
+ expect ( wrapperComponent . html ( ) ) . to . equal ( '<div><div foo="FOO"><span baz="qux">quux</span></div></div>' )
582
+ }
583
+ )
549
584
} )
0 commit comments