File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
packages/runtime-core/__tests__ Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -1272,4 +1272,41 @@ describe('api: watch', () => {
1272
1272
await nextTick ( )
1273
1273
expect ( cb ) . toHaveBeenCalledTimes ( 2 )
1274
1274
} )
1275
+
1276
+ it ( 'observation array depth' , async ( ) => {
1277
+ const arr = ref ( [
1278
+ {
1279
+ a : {
1280
+ b : 2
1281
+ }
1282
+ } ,
1283
+ {
1284
+ a : {
1285
+ b : 3
1286
+ }
1287
+ }
1288
+ ] )
1289
+ const cb = vi . fn ( )
1290
+ watch ( arr , cb , { deep : true , depth : 2 } )
1291
+
1292
+ arr . value [ 0 ] . a . b = 3
1293
+ await nextTick ( )
1294
+ expect ( cb ) . toHaveBeenCalledTimes ( 0 )
1295
+
1296
+ arr . value [ 0 ] . a = { b : 3 }
1297
+ await nextTick ( )
1298
+ expect ( cb ) . toHaveBeenCalledTimes ( 1 )
1299
+
1300
+ arr . value [ 1 ] . a = { b : 4 }
1301
+ await nextTick ( )
1302
+ expect ( cb ) . toHaveBeenCalledTimes ( 2 )
1303
+
1304
+ arr . value . push ( { a : { b : 5 } } )
1305
+ await nextTick ( )
1306
+ expect ( cb ) . toHaveBeenCalledTimes ( 3 )
1307
+
1308
+ arr . value . pop ( )
1309
+ await nextTick ( )
1310
+ expect ( cb ) . toHaveBeenCalledTimes ( 4 )
1311
+ } )
1275
1312
} )
You can’t perform that action at this time.
0 commit comments