1
1
const Vue = require ( 'vue/dist/vue.common.js' ) ;
2
- const { ref, reactive, watch } = require ( '../../src' ) ;
2
+ const { ref, reactive, watch, watchEffect } = require ( '../../src' ) ;
3
3
4
4
describe ( 'api/watch' , ( ) => {
5
5
const anyFn = expect . any ( Function ) ;
@@ -298,11 +298,11 @@ describe('api/watch', () => {
298
298
const x = ref ( 0 ) ;
299
299
300
300
// prettier-ignore
301
- watch ( ( ) => { void x . value ; result . push ( 'sync getter ' ) ; } , { flush : 'sync' } ) ;
301
+ watchEffect ( ( ) => { void x . value ; result . push ( 'sync effect ' ) ; } , { flush : 'sync' } ) ;
302
302
// prettier-ignore
303
- watch ( ( ) => { void x . value ; result . push ( 'pre getter ' ) ; } , { flush : 'pre' } ) ;
303
+ watchEffect ( ( ) => { void x . value ; result . push ( 'pre effect ' ) ; } , { flush : 'pre' } ) ;
304
304
// prettier-ignore
305
- watch ( ( ) => { void x . value ; result . push ( 'post getter ' ) ; } , { flush : 'post' } ) ;
305
+ watchEffect ( ( ) => { void x . value ; result . push ( 'post effect ' ) ; } , { flush : 'post' } ) ;
306
306
307
307
// prettier-ignore
308
308
watch ( x , ( ) => { result . push ( 'sync callback' ) } , { flush : 'sync' } )
@@ -321,24 +321,24 @@ describe('api/watch', () => {
321
321
} ,
322
322
template : `<div>{{x}}</div>` ,
323
323
} ) . $mount ( ) ;
324
- expect ( result ) . toEqual ( [ 'sync getter ' , 'sync callback' , 'pre callback' , 'post callback' ] ) ;
324
+ expect ( result ) . toEqual ( [ 'sync effect ' , 'sync callback' , 'pre callback' , 'post callback' ] ) ;
325
325
result . length = 0 ;
326
326
327
327
waitForUpdate ( ( ) => {
328
- expect ( result ) . toEqual ( [ 'pre getter ' , 'post getter ' ] ) ;
328
+ expect ( result ) . toEqual ( [ 'pre effect ' , 'post effect ' ] ) ;
329
329
result . length = 0 ;
330
330
331
331
vm . inc ( ) ;
332
332
} )
333
333
. then ( ( ) => {
334
334
expect ( result ) . toEqual ( [
335
335
'before inc' ,
336
- 'sync getter ' ,
336
+ 'sync effect ' ,
337
337
'sync callback' ,
338
338
'after inc' ,
339
- 'pre getter ' ,
339
+ 'pre effect ' ,
340
340
'pre callback' ,
341
- 'post getter ' ,
341
+ 'post effect ' ,
342
342
'post callback' ,
343
343
] ) ;
344
344
} )
@@ -352,7 +352,7 @@ describe('api/watch', () => {
352
352
const vm = new Vue ( {
353
353
setup ( ) {
354
354
const count = ref ( 0 ) ;
355
- watch ( _onCleanup => {
355
+ watchEffect ( _onCleanup => {
356
356
onCleanup = _onCleanup ;
357
357
spy ( count . value ) ;
358
358
renderedText = vm . $el . textContent ;
@@ -384,7 +384,7 @@ describe('api/watch', () => {
384
384
const vm = new Vue ( {
385
385
setup ( ) {
386
386
const count = ref ( 0 ) ;
387
- watch (
387
+ watchEffect (
388
388
( ) => {
389
389
spy ( count . value ) ;
390
390
} ,
@@ -563,7 +563,7 @@ describe('api/watch', () => {
563
563
564
564
it ( 'simple effect' , done => {
565
565
const obj = reactive ( { a : 1 } ) ;
566
- watch ( ( ) => spy ( obj . a ) ) ;
566
+ watchEffect ( ( ) => spy ( obj . a ) ) ;
567
567
expect ( spy ) . not . toHaveBeenCalled ( ) ;
568
568
waitForUpdate ( ( ) => {
569
569
expect ( spy ) . toBeCalledTimes ( 1 ) ;
@@ -596,10 +596,10 @@ describe('api/watch', () => {
596
596
return p ;
597
597
}
598
598
599
- it ( 'work with (single getter) ' , done => {
599
+ it ( 'work with effect ' , done => {
600
600
const id = ref ( 1 ) ;
601
601
const promises = [ ] ;
602
- watch ( onCleanup => {
602
+ watchEffect ( onCleanup => {
603
603
const val = getAsyncValue ( id . value ) ;
604
604
promises . push ( val ) ;
605
605
onCleanup ( ( ) => {
@@ -617,10 +617,10 @@ describe('api/watch', () => {
617
617
. then ( done ) ;
618
618
} ) ;
619
619
620
- it ( 'run cleanup when watch stops (single getter )' , done => {
620
+ it ( 'run cleanup when watch stops (effect )' , done => {
621
621
const spy = jest . fn ( ) ;
622
622
const cleanup = jest . fn ( ) ;
623
- const stop = watch ( onCleanup => {
623
+ const stop = watchEffect ( onCleanup => {
624
624
spy ( ) ;
625
625
onCleanup ( cleanup ) ;
626
626
} ) ;
@@ -651,7 +651,7 @@ describe('api/watch', () => {
651
651
it ( 'should not collect reactive in onCleanup' , done => {
652
652
const ref1 = ref ( 1 ) ;
653
653
const ref2 = ref ( 1 ) ;
654
- watch ( onCleanup => {
654
+ watchEffect ( onCleanup => {
655
655
spy ( ref1 . value ) ;
656
656
onCleanup ( ( ) => {
657
657
ref2 . value = ref2 . value + 1 ;
0 commit comments