@@ -23,13 +23,12 @@ describe('api/watch', () => {
23
23
} ,
24
24
template : `<div>{{a}}</div>` ,
25
25
} ) . $mount ( ) ;
26
- expect ( spy ) . toBeCalledTimes ( 1 ) ;
27
- expect ( spy ) . toHaveBeenLastCalledWith ( 1 , undefined , anyFn ) ;
26
+ expect ( spy ) . toBeCalledTimes ( 0 ) ;
28
27
vm . a = 2 ;
29
28
vm . a = 3 ;
30
- expect ( spy ) . toBeCalledTimes ( 1 ) ;
29
+ expect ( spy ) . toBeCalledTimes ( 0 ) ;
31
30
waitForUpdate ( ( ) => {
32
- expect ( spy ) . toBeCalledTimes ( 2 ) ;
31
+ expect ( spy ) . toBeCalledTimes ( 1 ) ;
33
32
expect ( spy ) . toHaveBeenLastCalledWith ( 3 , 1 , anyFn ) ;
34
33
} ) . then ( done ) ;
35
34
} ) ;
@@ -46,12 +45,11 @@ describe('api/watch', () => {
46
45
} ,
47
46
template : `<div>{{a}}</div>` ,
48
47
} ) . $mount ( ) ;
49
- expect ( spy ) . toBeCalledTimes ( 1 ) ;
50
- expect ( spy ) . toHaveBeenLastCalledWith ( 1 , undefined ) ;
48
+ expect ( spy ) . toBeCalledTimes ( 0 ) ;
51
49
vm . a = 2 ;
52
- expect ( spy ) . toBeCalledTimes ( 1 ) ;
50
+ expect ( spy ) . toBeCalledTimes ( 0 ) ;
53
51
waitForUpdate ( ( ) => {
54
- expect ( spy ) . toBeCalledTimes ( 2 ) ;
52
+ expect ( spy ) . toBeCalledTimes ( 1 ) ;
55
53
expect ( spy ) . toHaveBeenLastCalledWith ( 2 , 1 ) ;
56
54
} ) . then ( done ) ;
57
55
} ) ;
@@ -68,12 +66,11 @@ describe('api/watch', () => {
68
66
} ,
69
67
template : `<div>{{a}}</div>` ,
70
68
} ) . $mount ( ) ;
71
- expect ( spy ) . toBeCalledTimes ( 1 ) ;
72
- expect ( spy ) . toHaveBeenLastCalledWith ( 1 , undefined ) ;
69
+ expect ( spy ) . toBeCalledTimes ( 0 ) ;
73
70
vm . a = 2 ;
74
- expect ( spy ) . toBeCalledTimes ( 1 ) ;
71
+ expect ( spy ) . toBeCalledTimes ( 0 ) ;
75
72
waitForUpdate ( ( ) => {
76
- expect ( spy ) . toBeCalledTimes ( 2 ) ;
73
+ expect ( spy ) . toBeCalledTimes ( 1 ) ;
77
74
expect ( spy ) . toHaveBeenLastCalledWith ( 2 , 1 ) ;
78
75
} ) . then ( done ) ;
79
76
} ) ;
@@ -196,12 +193,11 @@ describe('api/watch', () => {
196
193
return h ( 'div' , this . a ) ;
197
194
} ,
198
195
} ) . $mount ( ) ;
199
- expect ( spy ) . toBeCalledTimes ( 1 ) ;
200
- expect ( spy ) . toHaveBeenLastCalledWith ( 1 , undefined ) ;
196
+ expect ( spy ) . toBeCalledTimes ( 0 ) ;
201
197
vm . a = 2 ;
202
198
waitForUpdate ( ( ) => {
203
199
expect ( rerenderedText ) . toBe ( '2' ) ;
204
- expect ( spy ) . toBeCalledTimes ( 2 ) ;
200
+ expect ( spy ) . toBeCalledTimes ( 1 ) ;
205
201
expect ( spy ) . toHaveBeenLastCalledWith ( 2 , 1 ) ;
206
202
} ) . then ( done ) ;
207
203
} ) ;
@@ -286,9 +282,8 @@ describe('api/watch', () => {
286
282
count . value ++ ;
287
283
} ,
288
284
} ) ;
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 ) ;
292
287
} ) ;
293
288
294
289
it ( 'should run in a expected order' , done => {
@@ -321,7 +316,7 @@ describe('api/watch', () => {
321
316
} ,
322
317
template : `<div>{{x}}</div>` ,
323
318
} ) . $mount ( ) ;
324
- expect ( result ) . toEqual ( [ 'sync effect' , 'sync callback' , 'pre callback' , 'post callback' ] ) ;
319
+ expect ( result ) . toEqual ( [ 'sync effect' ] ) ;
325
320
result . length = 0 ;
326
321
327
322
waitForUpdate ( ( ) => {
@@ -419,21 +414,20 @@ describe('api/watch', () => {
419
414
} ,
420
415
template : `<div>{{obj1.a}} {{obj2.a}}</div>` ,
421
416
} ) . $mount ( ) ;
422
- expect ( spy ) . toBeCalledTimes ( 1 ) ;
423
- expect ( spy ) . toHaveBeenLastCalledWith ( [ 1 , 2 ] , undefined ) ;
417
+ expect ( spy ) . toBeCalledTimes ( 0 ) ;
424
418
obj1 . a = 2 ;
425
419
obj2 . a = 3 ;
426
420
427
421
obj1 . a = 3 ;
428
422
obj2 . a = 4 ;
429
423
waitForUpdate ( ( ) => {
430
- expect ( spy ) . toBeCalledTimes ( 2 ) ;
424
+ expect ( spy ) . toBeCalledTimes ( 1 ) ;
431
425
expect ( spy ) . toHaveBeenLastCalledWith ( [ 3 , 4 ] , [ 1 , 2 ] ) ;
432
426
obj2 . a = 5 ;
433
427
obj2 . a = 6 ;
434
428
} )
435
429
. then ( ( ) => {
436
- expect ( spy ) . toBeCalledTimes ( 3 ) ;
430
+ expect ( spy ) . toBeCalledTimes ( 2 ) ;
437
431
expect ( spy ) . toHaveBeenLastCalledWith ( [ 3 , 6 ] , [ 3 , 4 ] ) ;
438
432
} )
439
433
. then ( done ) ;
@@ -553,10 +547,9 @@ describe('api/watch', () => {
553
547
it ( 'should work' , done => {
554
548
const obj = reactive ( { a : 1 } ) ;
555
549
watch ( ( ) => obj . a , ( n , o ) => spy ( n , o ) ) ;
556
- expect ( spy ) . toHaveBeenLastCalledWith ( 1 , undefined ) ;
557
550
obj . a = 2 ;
558
551
waitForUpdate ( ( ) => {
559
- expect ( spy ) . toBeCalledTimes ( 2 ) ;
552
+ expect ( spy ) . toBeCalledTimes ( 1 ) ;
560
553
expect ( spy ) . toHaveBeenLastCalledWith ( 2 , 1 ) ;
561
554
} ) . then ( done ) ;
562
555
} ) ;
@@ -634,7 +627,7 @@ describe('api/watch', () => {
634
627
. then ( done ) ;
635
628
} ) ;
636
629
637
- it ( 'run cleanup when watch stops' , ( ) => {
630
+ it ( 'run cleanup when watch stops' , done => {
638
631
const id = ref ( 1 ) ;
639
632
const spy = jest . fn ( ) ;
640
633
const cleanup = jest . fn ( ) ;
@@ -643,9 +636,16 @@ describe('api/watch', () => {
643
636
onCleanup ( cleanup ) ;
644
637
} ) ;
645
638
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 ) ;
649
649
} ) ;
650
650
651
651
it ( 'should not collect reactive in onCleanup' , done => {
@@ -675,19 +675,16 @@ describe('api/watch', () => {
675
675
676
676
it ( 'work with callback ' , done => {
677
677
const id = ref ( 1 ) ;
678
- const promises = [ ] ;
678
+ let promise ;
679
679
watch ( id , ( newVal , oldVal , onCleanup ) => {
680
680
const val = getAsyncValue ( newVal ) ;
681
- promises . push ( val ) ;
682
- onCleanup ( ( ) => {
683
- val . cancel ( ) ;
684
- } ) ;
681
+ promise = val ;
685
682
} ) ;
686
683
id . value = 2 ;
687
684
waitForUpdate ( )
688
685
. 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 ) ;
691
688
next ( ) ;
692
689
} )
693
690
. then ( done ) ;
0 commit comments