@@ -1689,6 +1689,57 @@ describe('api: watch', () => {
1689
1689
expect ( cb ) . toHaveBeenCalledTimes ( 4 )
1690
1690
} )
1691
1691
1692
+ test ( 'watching the same object at different depths' , async ( ) => {
1693
+ const arr1 : any [ ] = reactive ( [ [ [ { foo : { } } ] ] ] )
1694
+ const arr2 = arr1 [ 0 ]
1695
+ const arr3 = arr2 [ 0 ]
1696
+ const obj = arr3 [ 0 ]
1697
+ arr1 . push ( arr3 )
1698
+
1699
+ const cb1 = vi . fn ( )
1700
+ const cb2 = vi . fn ( )
1701
+ const cb3 = vi . fn ( )
1702
+ const cb4 = vi . fn ( )
1703
+ watch ( arr1 , cb1 , { deep : 1 } )
1704
+ watch ( arr1 , cb2 , { deep : 2 } )
1705
+ watch ( arr1 , cb3 , { deep : 3 } )
1706
+ watch ( arr1 , cb4 , { deep : 4 } )
1707
+
1708
+ await nextTick ( )
1709
+ expect ( cb1 ) . toHaveBeenCalledTimes ( 0 )
1710
+ expect ( cb2 ) . toHaveBeenCalledTimes ( 0 )
1711
+ expect ( cb3 ) . toHaveBeenCalledTimes ( 0 )
1712
+ expect ( cb4 ) . toHaveBeenCalledTimes ( 0 )
1713
+
1714
+ obj . foo = { }
1715
+ await nextTick ( )
1716
+ expect ( cb1 ) . toHaveBeenCalledTimes ( 0 )
1717
+ expect ( cb2 ) . toHaveBeenCalledTimes ( 0 )
1718
+ expect ( cb3 ) . toHaveBeenCalledTimes ( 1 )
1719
+ expect ( cb4 ) . toHaveBeenCalledTimes ( 1 )
1720
+
1721
+ obj . foo . bar = 1
1722
+ await nextTick ( )
1723
+ expect ( cb1 ) . toHaveBeenCalledTimes ( 0 )
1724
+ expect ( cb2 ) . toHaveBeenCalledTimes ( 0 )
1725
+ expect ( cb3 ) . toHaveBeenCalledTimes ( 1 )
1726
+ expect ( cb4 ) . toHaveBeenCalledTimes ( 2 )
1727
+
1728
+ arr3 . push ( obj . foo )
1729
+ await nextTick ( )
1730
+ expect ( cb1 ) . toHaveBeenCalledTimes ( 0 )
1731
+ expect ( cb2 ) . toHaveBeenCalledTimes ( 1 )
1732
+ expect ( cb3 ) . toHaveBeenCalledTimes ( 2 )
1733
+ expect ( cb4 ) . toHaveBeenCalledTimes ( 3 )
1734
+
1735
+ obj . foo . bar = 2
1736
+ await nextTick ( )
1737
+ expect ( cb1 ) . toHaveBeenCalledTimes ( 0 )
1738
+ expect ( cb2 ) . toHaveBeenCalledTimes ( 1 )
1739
+ expect ( cb3 ) . toHaveBeenCalledTimes ( 3 )
1740
+ expect ( cb4 ) . toHaveBeenCalledTimes ( 4 )
1741
+ } )
1742
+
1692
1743
test ( 'pause / resume' , async ( ) => {
1693
1744
const count = ref ( 0 )
1694
1745
const cb = vi . fn ( )
0 commit comments