@@ -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,58 @@ describeWithMountingMethods('options.slots', mountingMethod => {
546
550
wrapper . find ( 'div' ) . trigger ( 'click' )
547
551
}
548
552
)
553
+
554
+ itDoNotRunIf (
555
+ mountingMethod . name === 'renderToString' ,
556
+ 'mounts component with default slot if passed string in slot object' ,
557
+ ( ) => {
558
+ const wrapper1 = mount ( ComponentWithSlots , { slots : { default : 'foo<span>123</span>{{ foo }}' } } )
559
+ expect ( wrapper1 . find ( 'main' ) . html ( ) ) . to . equal ( '<main>foo<span>123</span>bar</main>' )
560
+ const wrapper2 = mount ( ComponentWithSlots , { slots : { default : '<p>1</p>{{ foo }}2' } } )
561
+ expect ( wrapper2 . find ( 'main' ) . html ( ) ) . to . equal ( '<main><p>1</p>bar2</main>' )
562
+ const wrapper3 = mount ( ComponentWithSlots , { slots : { default : '<p>1</p>{{ foo }}<p>2</p>' } } )
563
+ expect ( wrapper3 . find ( 'main' ) . html ( ) ) . to . equal ( '<main><p>1</p>bar<p>2</p></main>' )
564
+ const wrapper4 = mount ( ComponentWithSlots , { slots : { default : '123' } } )
565
+ expect ( wrapper4 . find ( 'main' ) . html ( ) ) . to . equal ( '<main>123</main>' )
566
+ const wrapper5 = mount ( ComponentWithSlots , { slots : { default : '1{{ foo }}2' } } )
567
+ expect ( wrapper5 . find ( 'main' ) . html ( ) ) . to . equal ( '<main>1bar2</main>' )
568
+ wrapper5 . trigger ( 'keydown' )
569
+ expect ( wrapper5 . find ( 'main' ) . html ( ) ) . to . equal ( '<main>1BAR2</main>' )
570
+ const wrapper6 = mount ( ComponentWithSlots , { slots : { default : '<p>1</p><p>2</p>' } } )
571
+ expect ( wrapper6 . find ( 'main' ) . html ( ) ) . to . equal ( '<main><p>1</p><p>2</p></main>' )
572
+ const wrapper7 = mount ( ComponentWithSlots , { slots : { default : '1<p>2</p>3' } } )
573
+ expect ( wrapper7 . find ( 'main' ) . html ( ) ) . to . equal ( '<main>1<p>2</p>3</main>' )
574
+ }
575
+ )
576
+
577
+ itDoNotRunIf (
578
+ mountingMethod . name === 'renderToString' ,
579
+ 'sets a component which can access the parent component' ,
580
+ ( ) => {
581
+ const localVue = createLocalVue ( )
582
+ localVue . prototype . bar = 'FOO'
583
+ const wrapperComponent = mount (
584
+ {
585
+ name : 'parentComponent' ,
586
+ template : '<div><slot /></div>' ,
587
+ data ( ) {
588
+ return {
589
+ childName : ''
590
+ }
591
+ }
592
+ } ,
593
+ {
594
+ components : {
595
+ ComponentWithParentName
596
+ } ,
597
+ slots : {
598
+ default : '<component-with-parent-name :foo="bar" />'
599
+ } ,
600
+ localVue
601
+ }
602
+ )
603
+ expect ( wrapperComponent . vm . childName ) . to . equal ( 'component-with-parent-name' )
604
+ expect ( wrapperComponent . html ( ) ) . to . equal ( '<div><div foo="FOO"><span baz="qux">quux</span></div></div>' )
605
+ }
606
+ )
549
607
} )
0 commit comments