@@ -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,60 @@ 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+ 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+ )
549611} )
0 commit comments