11import {
22 describeWithShallowAndMount ,
3- vueVersion ,
4- isRunningPhantomJS
3+ vueVersion
54} from '~resources/utils'
65import ComponentWithScopedSlots from '~resources/components/component-with-scoped-slots.vue'
76import { itDoNotRunIf } from 'conditional-specs'
@@ -14,7 +13,41 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
1413 } )
1514
1615 itDoNotRunIf (
17- vueVersion < 2.5 || isRunningPhantomJS ,
16+ vueVersion < 2.1 ,
17+ 'handles templates as the root node' , ( ) => {
18+ const wrapper = mountingMethod ( {
19+ template : '<div><slot name="single" :text="foo" :i="123"></slot></div>' ,
20+ data : ( ) => ( {
21+ foo : 'bar'
22+ } )
23+ } , {
24+ scopedSlots : {
25+ single : '<template><p>{{props.text}},{{props.i}}</p></template>'
26+ }
27+ } )
28+ expect ( wrapper . html ( ) ) . to . equal ( '<div><p>bar,123</p></div>' )
29+ } )
30+
31+ itDoNotRunIf (
32+ vueVersion < 2.1 ,
33+ 'handles render functions' , ( ) => {
34+ const wrapper = mountingMethod ( {
35+ template : '<div><slot name="single" :text="foo" /></div>' ,
36+ data : ( ) => ( {
37+ foo : 'bar'
38+ } )
39+ } , {
40+ scopedSlots : {
41+ single : function ( props ) {
42+ return this . $createElement ( 'p' , props . text )
43+ }
44+ }
45+ } )
46+ expect ( wrapper . html ( ) ) . to . equal ( '<div><p>bar</p></div>' )
47+ } )
48+
49+ itDoNotRunIf (
50+ vueVersion < 2.5 ,
1851 'mounts component scoped slots in render function' ,
1952 ( ) => {
2053 const destructuringWrapper = mountingMethod (
@@ -29,7 +62,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
2962 {
3063 scopedSlots : {
3164 default :
32- '<p slot-scope="{ index, item }">{{index}},{{item}}</p>'
65+ '<template slot-scope="{ index, item }"><p> {{index}},{{item}}</p></template >'
3366 }
3467 }
3568 )
@@ -38,16 +71,16 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
3871 const notDestructuringWrapper = mountingMethod (
3972 {
4073 render : function ( ) {
41- return this . $scopedSlots . default ( {
74+ return this . $scopedSlots . named ( {
4275 index : 1 ,
4376 item : 'foo'
4477 } )
4578 }
4679 } ,
4780 {
4881 scopedSlots : {
49- default :
50- '<p slot-scope="props ">{{props .index}},{{props .item}}</p>'
82+ named :
83+ '<p slot-scope="foo ">{{foo .index}},{{foo .item}}</p>'
5184 }
5285 }
5386 )
@@ -56,15 +89,15 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
5689 )
5790
5891 itDoNotRunIf (
59- vueVersion < 2.5 || isRunningPhantomJS ,
92+ vueVersion < 2.5 ,
6093 'mounts component scoped slots' ,
6194 ( ) => {
6295 const wrapper = mountingMethod ( ComponentWithScopedSlots , {
6396 slots : { default : '<span>123</span>' } ,
6497 scopedSlots : {
6598 destructuring :
6699 '<p slot-scope="{ index, item }">{{index}},{{item}}</p>' ,
67- list : '<p slot-scope="foo">{{foo.index}},{{foo.text}}</p>' ,
100+ list : '<template slot-scope="foo"><p> {{foo.index}},{{foo.text}}</p></template >' ,
68101 single : '<p slot-scope="bar">{{bar.text}}</p>' ,
69102 noProps : '<p slot-scope="baz">baz</p>'
70103 }
@@ -106,51 +139,43 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
106139 )
107140
108141 itDoNotRunIf (
109- vueVersion < 2.5 || isRunningPhantomJS ,
110- 'throws exception when it is seted to a template tag at top' ,
111- ( ) => {
112- const fn = ( ) => {
113- mountingMethod ( ComponentWithScopedSlots , {
114- scopedSlots : {
115- single : '<template></template>'
116- }
142+ vueVersion < 2.5 ,
143+ 'handles JSX' , ( ) => {
144+ const wrapper = mountingMethod ( {
145+ template : '<div><slot name="single" :text="foo"></slot></div>' ,
146+ data : ( ) => ( {
147+ foo : 'bar'
117148 } )
118- }
119- const message =
120- '[vue-test-utils]: the scopedSlots option does not support a template tag as the root element.'
121- expect ( fn )
122- . to . throw ( )
123- . with . property ( 'message' , message )
124- }
125- )
149+ } , {
150+ scopedSlots : {
151+ single ( { text } ) {
152+ return < p > { text } </ p >
153+ }
154+ }
155+ } )
156+ expect ( wrapper . html ( ) ) . to . equal ( '<div><p>bar</p></div>' )
157+ } )
126158
127159 itDoNotRunIf (
128- vueVersion >= 2.5 || isRunningPhantomJS ,
129- 'throws exception when vue version < 2.5' ,
130- ( ) => {
131- const fn = ( ) => {
132- mountingMethod ( ComponentWithScopedSlots , {
133- scopedSlots : {
134- list : '<p slot-scope="foo">{{foo.index}},{{foo.text}}</p>'
135- }
160+ vueVersion < 2.5 ,
161+ 'handles no slot-scope' , ( ) => {
162+ const wrapper = mountingMethod ( {
163+ template : '<div><slot name="single" :text="foo" :i="123"></slot></div>' ,
164+ data : ( ) => ( {
165+ foo : 'bar'
136166 } )
137- }
138- const message =
139- '[vue-test-utils]: the scopedSlots option is only supported in vue@2.5+.'
140- expect ( fn )
141- . to . throw ( )
142- . with . property ( 'message' , message )
143- }
144- )
167+ } , {
168+ scopedSlots : {
169+ single : '<p>{{props.text}},{{props.i}}</p>'
170+ }
171+ } )
172+ expect ( wrapper . html ( ) ) . to . equal ( '<div><p>bar,123</p></div>' )
173+ } )
145174
146175 itDoNotRunIf (
147- vueVersion < 2.5 ,
148- 'throws exception when using PhantomJS ' ,
176+ vueVersion > 2.0 ,
177+ 'throws exception when vue version < 2.1 ' ,
149178 ( ) => {
150- if ( window . navigator . userAgent . match ( / C h r o m e | P h a n t o m J S / i) ) {
151- return
152- }
153- window = { navigator : { userAgent : 'PhantomJS' } } // eslint-disable-line no-native-reassign
154179 const fn = ( ) => {
155180 mountingMethod ( ComponentWithScopedSlots , {
156181 scopedSlots : {
@@ -159,7 +184,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
159184 } )
160185 }
161186 const message =
162- '[vue-test-utils]: the scopedSlots option does not support PhantomJS. Please use Puppeteer, or pass a component .'
187+ '[vue-test-utils]: the scopedSlots option is only supported in vue@2.1+ .'
163188 expect ( fn )
164189 . to . throw ( )
165190 . with . property ( 'message' , message )
0 commit comments