This repository was archived by the owner on Jul 19, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +43
-1
lines changed
packages/runtime-core/__tests__ Expand file tree Collapse file tree 1 file changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -213,7 +213,7 @@ describe('component: slots', () => {
213
213
expect ( instance . slots . default ( ) ) . toMatchObject ( [ normalizeVNode ( 'footer' ) ] )
214
214
} )
215
215
216
- test ( 'should respect $stable flag' , async ( ) => {
216
+ test ( 'should respect $stable flag with a value of true ' , async ( ) => {
217
217
const flag1 = ref ( 1 )
218
218
const flag2 = ref ( 2 )
219
219
const spy = vi . fn ( )
@@ -255,6 +255,48 @@ describe('component: slots', () => {
255
255
expect ( spy ) . toHaveBeenCalledTimes ( 2 )
256
256
} )
257
257
258
+ test ( 'should respect $stable flag with a value of false' , async ( ) => {
259
+ const flag1 = ref ( 1 )
260
+ const flag2 = ref ( 2 )
261
+ const spy = vi . fn ( )
262
+
263
+ const Child = ( ) => {
264
+ spy ( )
265
+ return 'child'
266
+ }
267
+
268
+ const App = {
269
+ setup ( ) {
270
+ return ( ) => [
271
+ flag1 . value ,
272
+ h (
273
+ Child ,
274
+ { n : flag2 . value } ,
275
+ {
276
+ foo : ( ) => 'foo' ,
277
+ $stable : false ,
278
+ } ,
279
+ ) ,
280
+ ]
281
+ } ,
282
+ }
283
+
284
+ render ( h ( App ) , nodeOps . createElement ( 'div' ) )
285
+ expect ( spy ) . toHaveBeenCalledTimes ( 1 )
286
+
287
+ // parent re-render, props didn't change, slots are not stable
288
+ // -> child should update
289
+ flag1 . value ++
290
+ await nextTick ( )
291
+ expect ( spy ) . toHaveBeenCalledTimes ( 2 )
292
+
293
+ // parent re-render, props changed
294
+ // -> child should update
295
+ flag2 . value ++
296
+ await nextTick ( )
297
+ expect ( spy ) . toHaveBeenCalledTimes ( 3 )
298
+ } )
299
+
258
300
test ( 'should not warn when mounting another app in setup' , ( ) => {
259
301
const Comp = {
260
302
setup ( _ : any , { slots } : any ) {
You can’t perform that action at this time.
0 commit comments