@@ -96,6 +96,30 @@ describe('api: watch', () => {
96
96
expect ( spy ) . toBeCalledWith ( [ 1 ] , [ 1 ] , expect . anything ( ) )
97
97
} )
98
98
99
+ it ( 'should not call functions inside a reactive source array' , ( ) => {
100
+ const spy1 = vi . fn ( )
101
+ const array = reactive ( [ spy1 ] )
102
+ const spy2 = vi . fn ( )
103
+ watch ( array , spy2 , { immediate : true } )
104
+ expect ( spy1 ) . toBeCalledTimes ( 0 )
105
+ expect ( spy2 ) . toBeCalledWith ( [ spy1 ] , undefined , expect . anything ( ) )
106
+ } )
107
+
108
+ it ( 'should not unwrap refs in a reactive source array' , async ( ) => {
109
+ const val = ref ( { foo : 1 } )
110
+ const array = reactive ( [ val ] )
111
+ const spy = vi . fn ( )
112
+ watch ( array , spy , { immediate : true } )
113
+ expect ( spy ) . toBeCalledTimes ( 1 )
114
+ expect ( spy ) . toBeCalledWith ( [ val ] , undefined , expect . anything ( ) )
115
+
116
+ // deep by default
117
+ val . value . foo ++
118
+ await nextTick ( )
119
+ expect ( spy ) . toBeCalledTimes ( 2 )
120
+ expect ( spy ) . toBeCalledWith ( [ val ] , [ val ] , expect . anything ( ) )
121
+ } )
122
+
99
123
it ( 'should not fire if watched getter result did not change' , async ( ) => {
100
124
const spy = vi . fn ( )
101
125
const n = ref ( 0 )
@@ -186,6 +210,24 @@ describe('api: watch', () => {
186
210
expect ( dummy ) . toBe ( 1 )
187
211
} )
188
212
213
+ it ( 'directly watching reactive array with explicit deep: false' , async ( ) => {
214
+ const val = ref ( 1 )
215
+ const array : any [ ] = reactive ( [ val ] )
216
+ const spy = vi . fn ( )
217
+ watch ( array , spy , { immediate : true , deep : false } )
218
+ expect ( spy ) . toBeCalledTimes ( 1 )
219
+ expect ( spy ) . toBeCalledWith ( [ val ] , undefined , expect . anything ( ) )
220
+
221
+ val . value ++
222
+ await nextTick ( )
223
+ expect ( spy ) . toBeCalledTimes ( 1 )
224
+
225
+ array [ 1 ] = 2
226
+ await nextTick ( )
227
+ expect ( spy ) . toBeCalledTimes ( 2 )
228
+ expect ( spy ) . toBeCalledWith ( [ val , 2 ] , [ val , 2 ] , expect . anything ( ) )
229
+ } )
230
+
189
231
// #9916
190
232
it ( 'watching shallow reactive array with deep: false' , async ( ) => {
191
233
class foo {
0 commit comments