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