1
1
import {
2
2
describeWithShallowAndMount ,
3
- vueVersion ,
4
- isRunningPhantomJS
3
+ vueVersion
5
4
} from '~resources/utils'
6
5
import ComponentWithScopedSlots from '~resources/components/component-with-scoped-slots.vue'
7
6
import { itDoNotRunIf } from 'conditional-specs'
@@ -14,7 +13,41 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
14
13
} )
15
14
16
15
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 ,
18
51
'mounts component scoped slots in render function' ,
19
52
( ) => {
20
53
const destructuringWrapper = mountingMethod (
@@ -29,7 +62,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
29
62
{
30
63
scopedSlots : {
31
64
default :
32
- '<p slot-scope="{ index, item }">{{index}},{{item}}</p>'
65
+ '<template slot-scope="{ index, item }"><p> {{index}},{{item}}</p></template >'
33
66
}
34
67
}
35
68
)
@@ -38,16 +71,16 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
38
71
const notDestructuringWrapper = mountingMethod (
39
72
{
40
73
render : function ( ) {
41
- return this . $scopedSlots . default ( {
74
+ return this . $scopedSlots . named ( {
42
75
index : 1 ,
43
76
item : 'foo'
44
77
} )
45
78
}
46
79
} ,
47
80
{
48
81
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>'
51
84
}
52
85
}
53
86
)
@@ -56,15 +89,15 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
56
89
)
57
90
58
91
itDoNotRunIf (
59
- vueVersion < 2.5 || isRunningPhantomJS ,
92
+ vueVersion < 2.5 ,
60
93
'mounts component scoped slots' ,
61
94
( ) => {
62
95
const wrapper = mountingMethod ( ComponentWithScopedSlots , {
63
96
slots : { default : '<span>123</span>' } ,
64
97
scopedSlots : {
65
98
destructuring :
66
99
'<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 >' ,
68
101
single : '<p slot-scope="bar">{{bar.text}}</p>' ,
69
102
noProps : '<p slot-scope="baz">baz</p>'
70
103
}
@@ -106,51 +139,43 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
106
139
)
107
140
108
141
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'
117
148
} )
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
+ } )
126
158
127
159
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'
136
166
} )
137
- }
138
- const message =
139
- '[vue-test-utils]: the scopedSlots option is only supported in [email protected] +.'
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
+ } )
145
174
146
175
itDoNotRunIf (
147
- vueVersion < 2.5 ,
148
- 'throws exception when using PhantomJS ' ,
176
+ vueVersion > 2.0 ,
177
+ 'throws exception when vue version < 2.1 ' ,
149
178
( ) => {
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
154
179
const fn = ( ) => {
155
180
mountingMethod ( ComponentWithScopedSlots , {
156
181
scopedSlots : {
@@ -159,7 +184,7 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
159
184
} )
160
185
}
161
186
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 [email protected] + .'
163
188
expect ( fn )
164
189
. to . throw ( )
165
190
. with . property ( 'message' , message )
0 commit comments