@@ -2,8 +2,10 @@ import { compileToFunctions } from 'vue-template-compiler'
22import Component from '~resources/components/component.vue'
33import ComponentWithSlots from '~resources/components/component-with-slots.vue'
44import ComponentAsAClass from '~resources/components/component-as-a-class.vue'
5+ import ComponentWithParentName from '~resources/components/component-with-parent-name.vue'
56import { describeWithMountingMethods , vueVersion } from '~resources/utils'
67import { itSkipIf , itDoNotRunIf } from 'conditional-specs'
8+ import { mount , createLocalVue } from '~vue/test-utils'
79
810describeWithMountingMethods ( 'options.slots' , mountingMethod => {
911 it ( 'mounts component with default slot if passed component in slot object' , ( ) => {
@@ -224,14 +226,18 @@ describeWithMountingMethods('options.slots', mountingMethod => {
224226 it ( 'mounts component with text slot' , ( ) => {
225227 const wrapper = mountingMethod ( ComponentWithSlots , {
226228 slots : {
227- default : 'hello,' ,
228- header : 'world'
229+ header : 'hello,' ,
230+ default : 'world'
229231 }
230232 } )
231233 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+ )
233237 } 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+ )
235241 }
236242 } )
237243
@@ -546,4 +552,58 @@ describeWithMountingMethods('options.slots', mountingMethod => {
546552 wrapper . find ( 'div' ) . trigger ( 'click' )
547553 }
548554 )
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+ }
577+ )
578+
579+ itDoNotRunIf (
580+ mountingMethod . name === 'renderToString' ,
581+ 'sets a component which can access the parent component' ,
582+ ( ) => {
583+ const localVue = createLocalVue ( )
584+ localVue . prototype . bar = 'FOO'
585+ const wrapperComponent = mount (
586+ {
587+ name : 'parentComponent' ,
588+ template : '<div><slot /></div>' ,
589+ data ( ) {
590+ return {
591+ childName : ''
592+ }
593+ }
594+ } ,
595+ {
596+ components : {
597+ ComponentWithParentName
598+ } ,
599+ slots : {
600+ default : '<component-with-parent-name :foo="bar" />'
601+ } ,
602+ localVue
603+ }
604+ )
605+ expect ( wrapperComponent . vm . childName ) . to . equal ( 'component-with-parent-name' )
606+ expect ( wrapperComponent . html ( ) ) . to . equal ( '<div><div foo="FOO"><span baz="qux">quux</span></div></div>' )
607+ }
608+ )
549609} )
0 commit comments