@@ -2,6 +2,7 @@ import { compileToFunctions } from 'vue-template-compiler'
22import mount from '~src/mount'
33import Component from '~resources/components/component.vue'
44import ComponentWithSlots from '~resources/components/component-with-slots.vue'
5+ import { vueVersion } from '~resources/test-utils'
56
67describe ( 'mount.slots' , ( ) => {
78 it ( 'mounts component with default slot if passed component in slot object' , ( ) => {
@@ -25,6 +26,17 @@ describe('mount.slots', () => {
2526 expect ( wrapper . contains ( 'span' ) ) . to . equal ( true )
2627 } )
2728
29+ it ( 'mounts component with default slot if passed string in slot object' , ( ) => {
30+ if ( vueVersion >= 2.2 ) {
31+ const wrapper = mount ( ComponentWithSlots , { slots : { default : 'foo' } } )
32+ expect ( wrapper . find ( 'main' ) . text ( ) ) . to . equal ( 'foo' )
33+ } else {
34+ const message = '[vue-test-utils]: vue-test-utils support for passing text to slots at vue@2.2+'
35+ const fn = ( ) => mount ( ComponentWithSlots , { slots : { default : 'foo' } } )
36+ expect ( fn ) . to . throw ( ) . with . property ( 'message' , message )
37+ }
38+ } )
39+
2840 it ( 'throws error if passed string in default slot object and vue-template-compiler is undefined' , ( ) => {
2941 const compilerSave = require . cache [ require . resolve ( 'vue-template-compiler' ) ] . exports . compileToFunctions
3042 require . cache [ require . resolve ( 'vue-template-compiler' ) ] . exports . compileToFunctions = undefined
@@ -46,6 +58,17 @@ describe('mount.slots', () => {
4658 expect ( wrapper . contains ( 'span' ) ) . to . equal ( true )
4759 } )
4860
61+ it ( 'mounts component with default slot if passed string in slot text array object' , ( ) => {
62+ if ( vueVersion >= 2.2 ) {
63+ const wrapper = mount ( ComponentWithSlots , { slots : { default : [ 'foo' , 'bar' ] } } )
64+ expect ( wrapper . find ( 'main' ) . text ( ) ) . to . equal ( 'foobar' )
65+ } else {
66+ const message = '[vue-test-utils]: vue-test-utils support for passing text to slots at vue@2.2+'
67+ const fn = ( ) => mount ( ComponentWithSlots , { slots : { default : [ 'foo' , 'bar' ] } } )
68+ expect ( fn ) . to . throw ( ) . with . property ( 'message' , message )
69+ }
70+ } )
71+
4972 it ( 'throws error if passed string in default slot array vue-template-compiler is undefined' , ( ) => {
5073 const compilerSave = require . cache [ require . resolve ( 'vue-template-compiler' ) ] . exports . compileToFunctions
5174 require . cache [ require . resolve ( 'vue-template-compiler' ) ] . exports . compileToFunctions = undefined
0 commit comments