8
8
nextTick ,
9
9
ref ,
10
10
template ,
11
- withCtx ,
12
11
} from '../src'
13
12
import { makeRender } from './_utils'
14
13
@@ -35,21 +34,6 @@ function renderWithSlots(slots: any): any {
35
34
}
36
35
37
36
describe ( 'component: slots' , ( ) => {
38
- test ( 'initSlots: instance.slots should be set correctly' , ( ) => {
39
- const { slots } = renderWithSlots ( { _ : 1 } )
40
- expect ( slots ) . toMatchObject ( { _ : 1 } )
41
- } )
42
-
43
- // NOTE: slot normalization is not supported
44
- test . todo (
45
- 'initSlots: should normalize object slots (when value is null, string, array)' ,
46
- ( ) => { } ,
47
- )
48
- test . todo (
49
- 'initSlots: should normalize object slots (when value is function)' ,
50
- ( ) => { } ,
51
- )
52
-
53
37
test ( 'initSlots: instance.slots should be set correctly' , ( ) => {
54
38
let instance : any
55
39
const Comp = defineComponent ( {
@@ -74,6 +58,16 @@ describe('component: slots', () => {
74
58
)
75
59
} )
76
60
61
+ // NOTE: slot normalization is not supported
62
+ test . todo (
63
+ 'initSlots: should normalize object slots (when value is null, string, array)' ,
64
+ ( ) => { } ,
65
+ )
66
+ test . todo (
67
+ 'initSlots: should normalize object slots (when value is function)' ,
68
+ ( ) => { } ,
69
+ )
70
+
77
71
// runtime-core's "initSlots: instance.slots should be set correctly (when vnode.shapeFlag is not SLOTS_CHILDREN)"
78
72
test ( 'initSlots: instance.slots should be set correctly' , ( ) => {
79
73
const { slots } = renderWithSlots ( {
@@ -154,12 +148,16 @@ describe('component: slots', () => {
154
148
} )
155
149
156
150
test ( 'the current instance should be kept in the slot' , async ( ) => {
157
- let instanceInSlot : any
151
+ let instanceInDefaultSlot : any
152
+ let instanceInVForSlot : any
153
+ let instanceInVIfSlot : any
158
154
159
155
const Comp = defineComponent ( {
160
156
render ( ) {
161
157
const instance = getCurrentInstance ( )
162
158
instance ! . slots . default ! ( )
159
+ instance ! . slots . inVFor ! ( )
160
+ instance ! . slots . inVIf ! ( )
163
161
return template ( '<div></div>' ) ( )
164
162
} ,
165
163
} )
@@ -170,16 +168,37 @@ describe('component: slots', () => {
170
168
Comp ,
171
169
{ } ,
172
170
{
173
- default : withCtx ( ( ) => {
174
- instanceInSlot = getCurrentInstance ( )
171
+ default : ( ) => {
172
+ instanceInDefaultSlot = getCurrentInstance ( )
175
173
return template ( 'content' ) ( )
176
- } ) ,
174
+ } ,
177
175
} ,
176
+ ( ) => [
177
+ [
178
+ {
179
+ name : 'inVFor' ,
180
+ fn : ( ) => {
181
+ instanceInVForSlot = getCurrentInstance ( )
182
+ return template ( 'content' ) ( )
183
+ } ,
184
+ } ,
185
+ ] ,
186
+ {
187
+ name : 'inVIf' ,
188
+ key : '1' ,
189
+ fn : ( ) => {
190
+ instanceInVIfSlot = getCurrentInstance ( )
191
+ return template ( 'content' ) ( )
192
+ } ,
193
+ } ,
194
+ ] ,
178
195
)
179
196
} ,
180
197
} ) . render ( )
181
198
182
- expect ( instanceInSlot ) . toBe ( instance )
199
+ expect ( instanceInDefaultSlot ) . toBe ( instance )
200
+ expect ( instanceInVForSlot ) . toBe ( instance )
201
+ expect ( instanceInVIfSlot ) . toBe ( instance )
183
202
} )
184
203
185
204
test . todo ( 'should respect $stable flag' , async ( ) => {
0 commit comments