@@ -23,13 +23,12 @@ describe('api/watch', () => {
2323 } ,
2424 template : `<div>{{a}}</div>` ,
2525 } ) . $mount ( ) ;
26- expect ( spy ) . toBeCalledTimes ( 1 ) ;
27- expect ( spy ) . toHaveBeenLastCalledWith ( 1 , undefined , anyFn ) ;
26+ expect ( spy ) . toBeCalledTimes ( 0 ) ;
2827 vm . a = 2 ;
2928 vm . a = 3 ;
30- expect ( spy ) . toBeCalledTimes ( 1 ) ;
29+ expect ( spy ) . toBeCalledTimes ( 0 ) ;
3130 waitForUpdate ( ( ) => {
32- expect ( spy ) . toBeCalledTimes ( 2 ) ;
31+ expect ( spy ) . toBeCalledTimes ( 1 ) ;
3332 expect ( spy ) . toHaveBeenLastCalledWith ( 3 , 1 , anyFn ) ;
3433 } ) . then ( done ) ;
3534 } ) ;
@@ -46,12 +45,11 @@ describe('api/watch', () => {
4645 } ,
4746 template : `<div>{{a}}</div>` ,
4847 } ) . $mount ( ) ;
49- expect ( spy ) . toBeCalledTimes ( 1 ) ;
50- expect ( spy ) . toHaveBeenLastCalledWith ( 1 , undefined ) ;
48+ expect ( spy ) . toBeCalledTimes ( 0 ) ;
5149 vm . a = 2 ;
52- expect ( spy ) . toBeCalledTimes ( 1 ) ;
50+ expect ( spy ) . toBeCalledTimes ( 0 ) ;
5351 waitForUpdate ( ( ) => {
54- expect ( spy ) . toBeCalledTimes ( 2 ) ;
52+ expect ( spy ) . toBeCalledTimes ( 1 ) ;
5553 expect ( spy ) . toHaveBeenLastCalledWith ( 2 , 1 ) ;
5654 } ) . then ( done ) ;
5755 } ) ;
@@ -68,12 +66,11 @@ describe('api/watch', () => {
6866 } ,
6967 template : `<div>{{a}}</div>` ,
7068 } ) . $mount ( ) ;
71- expect ( spy ) . toBeCalledTimes ( 1 ) ;
72- expect ( spy ) . toHaveBeenLastCalledWith ( 1 , undefined ) ;
69+ expect ( spy ) . toBeCalledTimes ( 0 ) ;
7370 vm . a = 2 ;
74- expect ( spy ) . toBeCalledTimes ( 1 ) ;
71+ expect ( spy ) . toBeCalledTimes ( 0 ) ;
7572 waitForUpdate ( ( ) => {
76- expect ( spy ) . toBeCalledTimes ( 2 ) ;
73+ expect ( spy ) . toBeCalledTimes ( 1 ) ;
7774 expect ( spy ) . toHaveBeenLastCalledWith ( 2 , 1 ) ;
7875 } ) . then ( done ) ;
7976 } ) ;
@@ -196,12 +193,11 @@ describe('api/watch', () => {
196193 return h ( 'div' , this . a ) ;
197194 } ,
198195 } ) . $mount ( ) ;
199- expect ( spy ) . toBeCalledTimes ( 1 ) ;
200- expect ( spy ) . toHaveBeenLastCalledWith ( 1 , undefined ) ;
196+ expect ( spy ) . toBeCalledTimes ( 0 ) ;
201197 vm . a = 2 ;
202198 waitForUpdate ( ( ) => {
203199 expect ( rerenderedText ) . toBe ( '2' ) ;
204- expect ( spy ) . toBeCalledTimes ( 2 ) ;
200+ expect ( spy ) . toBeCalledTimes ( 1 ) ;
205201 expect ( spy ) . toHaveBeenLastCalledWith ( 2 , 1 ) ;
206202 } ) . then ( done ) ;
207203 } ) ;
@@ -286,9 +282,8 @@ describe('api/watch', () => {
286282 count . value ++ ;
287283 } ,
288284 } ) ;
289- expect ( spy ) . toBeCalledTimes ( 2 ) ;
290- expect ( spy ) . toHaveBeenNthCalledWith ( 1 , 0 , undefined ) ;
291- expect ( spy ) . toHaveBeenNthCalledWith ( 2 , 1 , 0 ) ;
285+ expect ( spy ) . toBeCalledTimes ( 1 ) ;
286+ expect ( spy ) . toHaveBeenNthCalledWith ( 1 , 1 , 0 ) ;
292287 } ) ;
293288
294289 it ( 'should run in a expected order' , done => {
@@ -321,7 +316,7 @@ describe('api/watch', () => {
321316 } ,
322317 template : `<div>{{x}}</div>` ,
323318 } ) . $mount ( ) ;
324- expect ( result ) . toEqual ( [ 'sync effect' , 'sync callback' , 'pre callback' , 'post callback' ] ) ;
319+ expect ( result ) . toEqual ( [ 'sync effect' ] ) ;
325320 result . length = 0 ;
326321
327322 waitForUpdate ( ( ) => {
@@ -419,21 +414,20 @@ describe('api/watch', () => {
419414 } ,
420415 template : `<div>{{obj1.a}} {{obj2.a}}</div>` ,
421416 } ) . $mount ( ) ;
422- expect ( spy ) . toBeCalledTimes ( 1 ) ;
423- expect ( spy ) . toHaveBeenLastCalledWith ( [ 1 , 2 ] , undefined ) ;
417+ expect ( spy ) . toBeCalledTimes ( 0 ) ;
424418 obj1 . a = 2 ;
425419 obj2 . a = 3 ;
426420
427421 obj1 . a = 3 ;
428422 obj2 . a = 4 ;
429423 waitForUpdate ( ( ) => {
430- expect ( spy ) . toBeCalledTimes ( 2 ) ;
424+ expect ( spy ) . toBeCalledTimes ( 1 ) ;
431425 expect ( spy ) . toHaveBeenLastCalledWith ( [ 3 , 4 ] , [ 1 , 2 ] ) ;
432426 obj2 . a = 5 ;
433427 obj2 . a = 6 ;
434428 } )
435429 . then ( ( ) => {
436- expect ( spy ) . toBeCalledTimes ( 3 ) ;
430+ expect ( spy ) . toBeCalledTimes ( 2 ) ;
437431 expect ( spy ) . toHaveBeenLastCalledWith ( [ 3 , 6 ] , [ 3 , 4 ] ) ;
438432 } )
439433 . then ( done ) ;
@@ -553,10 +547,9 @@ describe('api/watch', () => {
553547 it ( 'should work' , done => {
554548 const obj = reactive ( { a : 1 } ) ;
555549 watch ( ( ) => obj . a , ( n , o ) => spy ( n , o ) ) ;
556- expect ( spy ) . toHaveBeenLastCalledWith ( 1 , undefined ) ;
557550 obj . a = 2 ;
558551 waitForUpdate ( ( ) => {
559- expect ( spy ) . toBeCalledTimes ( 2 ) ;
552+ expect ( spy ) . toBeCalledTimes ( 1 ) ;
560553 expect ( spy ) . toHaveBeenLastCalledWith ( 2 , 1 ) ;
561554 } ) . then ( done ) ;
562555 } ) ;
@@ -634,7 +627,7 @@ describe('api/watch', () => {
634627 . then ( done ) ;
635628 } ) ;
636629
637- it ( 'run cleanup when watch stops' , ( ) => {
630+ it ( 'run cleanup when watch stops' , done => {
638631 const id = ref ( 1 ) ;
639632 const spy = jest . fn ( ) ;
640633 const cleanup = jest . fn ( ) ;
@@ -643,9 +636,16 @@ describe('api/watch', () => {
643636 onCleanup ( cleanup ) ;
644637 } ) ;
645638
646- expect ( spy ) . toHaveBeenCalledWith ( 1 ) ;
647- stop ( ) ;
648- expect ( cleanup ) . toHaveBeenCalled ( ) ;
639+ id . value = 2 ;
640+
641+ waitForUpdate ( ( ) => {
642+ expect ( spy ) . toHaveBeenLastCalledWith ( 2 ) ;
643+ stop ( ) ;
644+ } )
645+ . then ( ( ) => {
646+ expect ( cleanup ) . toHaveBeenCalled ( ) ;
647+ } )
648+ . then ( done ) ;
649649 } ) ;
650650
651651 it ( 'should not collect reactive in onCleanup' , done => {
@@ -675,19 +675,16 @@ describe('api/watch', () => {
675675
676676 it ( 'work with callback ' , done => {
677677 const id = ref ( 1 ) ;
678- const promises = [ ] ;
678+ let promise ;
679679 watch ( id , ( newVal , oldVal , onCleanup ) => {
680680 const val = getAsyncValue ( newVal ) ;
681- promises . push ( val ) ;
682- onCleanup ( ( ) => {
683- val . cancel ( ) ;
684- } ) ;
681+ promise = val ;
685682 } ) ;
686683 id . value = 2 ;
687684 waitForUpdate ( )
688685 . thenWaitFor ( async next => {
689- const values = await Promise . all ( promises ) ;
690- expect ( values ) . toEqual ( [ 'canceled' , 2 ] ) ;
686+ const value = await promise ;
687+ expect ( value ) . toEqual ( 2 ) ;
691688 next ( ) ;
692689 } )
693690 . then ( done ) ;
0 commit comments