@@ -34,21 +34,6 @@ function renderWithSlots(slots: any): any {
34
34
}
35
35
36
36
describe ( 'component: slots' , ( ) => {
37
- test ( 'initSlots: instance.slots should be set correctly' , ( ) => {
38
- const { slots } = renderWithSlots ( { _ : 1 } )
39
- expect ( slots ) . toMatchObject ( { _ : 1 } )
40
- } )
41
-
42
- // NOTE: slot normalization is not supported
43
- test . todo (
44
- 'initSlots: should normalize object slots (when value is null, string, array)' ,
45
- ( ) => { } ,
46
- )
47
- test . todo (
48
- 'initSlots: should normalize object slots (when value is function)' ,
49
- ( ) => { } ,
50
- )
51
-
52
37
test ( 'initSlots: instance.slots should be set correctly' , ( ) => {
53
38
let instance : any
54
39
const Comp = defineComponent ( {
@@ -73,6 +58,16 @@ describe('component: slots', () => {
73
58
)
74
59
} )
75
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
+
76
71
// runtime-core's "initSlots: instance.slots should be set correctly (when vnode.shapeFlag is not SLOTS_CHILDREN)"
77
72
test ( 'initSlots: instance.slots should be set correctly' , ( ) => {
78
73
const { slots } = renderWithSlots ( {
@@ -152,6 +147,60 @@ describe('component: slots', () => {
152
147
expect ( instance . slots ) . toHaveProperty ( 'footer' )
153
148
} )
154
149
150
+ test ( 'the current instance should be kept in the slot' , async ( ) => {
151
+ let instanceInDefaultSlot : any
152
+ let instanceInVForSlot : any
153
+ let instanceInVIfSlot : any
154
+
155
+ const Comp = defineComponent ( {
156
+ render ( ) {
157
+ const instance = getCurrentInstance ( )
158
+ instance ! . slots . default ! ( )
159
+ instance ! . slots . inVFor ! ( )
160
+ instance ! . slots . inVIf ! ( )
161
+ return template ( '<div></div>' ) ( )
162
+ } ,
163
+ } )
164
+
165
+ const { instance } = define ( {
166
+ render ( ) {
167
+ return createComponent (
168
+ Comp ,
169
+ { } ,
170
+ {
171
+ default : ( ) => {
172
+ instanceInDefaultSlot = getCurrentInstance ( )
173
+ return template ( 'content' ) ( )
174
+ } ,
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
+ ] ,
195
+ )
196
+ } ,
197
+ } ) . render ( )
198
+
199
+ expect ( instanceInDefaultSlot ) . toBe ( instance )
200
+ expect ( instanceInVForSlot ) . toBe ( instance )
201
+ expect ( instanceInVIfSlot ) . toBe ( instance )
202
+ } )
203
+
155
204
test . todo ( 'should respect $stable flag' , async ( ) => {
156
205
// TODO: $stable flag?
157
206
} )
0 commit comments