File tree Expand file tree Collapse file tree 2 files changed +49
-2
lines changed Expand file tree Collapse file tree 2 files changed +49
-2
lines changed Original file line number Diff line number Diff line change @@ -103,8 +103,6 @@ function getWatcherOption(options?: Partial<WatchOptions>): WatchOptions {
103
103
function getWatchEffectOption ( options ?: Partial < WatchOptions > ) : WatchOptions {
104
104
return {
105
105
...{
106
- immediate : true ,
107
- deep : false ,
108
106
flush : 'pre' ,
109
107
} ,
110
108
...options ,
@@ -208,6 +206,21 @@ function createWatcher(
208
206
cb : WatchCallback < any > | null ,
209
207
options : WatchOptions
210
208
) : ( ) => void {
209
+ if ( __DEV__ && ! cb ) {
210
+ if ( options . immediate !== undefined ) {
211
+ warn (
212
+ `watch() "immediate" option is only respected when using the ` +
213
+ `watch(source, callback, options?) signature.`
214
+ )
215
+ }
216
+ if ( options . deep !== undefined ) {
217
+ warn (
218
+ `watch() "deep" option is only respected when using the ` +
219
+ `watch(source, callback, options?) signature.`
220
+ )
221
+ }
222
+ }
223
+
211
224
const flushMode = options . flush
212
225
const isSync = flushMode === 'sync'
213
226
let cleanup : ( ( ) => void ) | null
Original file line number Diff line number Diff line change @@ -446,6 +446,40 @@ describe('api/watch', () => {
446
446
vm . count ++
447
447
expect ( spy ) . toHaveBeenLastCalledWith ( 1 )
448
448
} )
449
+
450
+ it ( 'warn immediate option when using effect' , async ( ) => {
451
+ const count = ref ( 0 )
452
+ let dummy
453
+ watchEffect (
454
+ ( ) => {
455
+ dummy = count . value
456
+ } ,
457
+ { immediate : false }
458
+ )
459
+ expect ( dummy ) . toBe ( 0 )
460
+ expect ( `"immediate" option is only respected` ) . toHaveBeenWarned ( )
461
+
462
+ count . value ++
463
+ await nextTick ( )
464
+ expect ( dummy ) . toBe ( 1 )
465
+ } )
466
+
467
+ it ( 'warn and not respect deep option when using effect' , async ( ) => {
468
+ const arr = ref ( [ 1 , [ 2 ] ] )
469
+ const spy = jest . fn ( )
470
+ watchEffect (
471
+ ( ) => {
472
+ spy ( )
473
+ return arr
474
+ } ,
475
+ { deep : true }
476
+ )
477
+ expect ( spy ) . toHaveBeenCalledTimes ( 1 )
478
+ arr . value [ 1 ] [ 0 ] = 3
479
+ await nextTick ( )
480
+ expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ,
481
+ expect ( `"deep" option is only respected` ) . toHaveBeenWarned ( )
482
+ } )
449
483
} )
450
484
451
485
describe ( 'Multiple sources' , ( ) => {
You can’t perform that action at this time.
0 commit comments