@@ -26,16 +26,19 @@ describe('UNIT: ViewModel', function () {
26
26
27
27
describe ( '.$watch()' , function ( ) {
28
28
29
- it ( 'should trigger callback when a plain value changes' , function ( ) {
29
+ it ( 'should trigger callback when a plain value changes' , function ( done ) {
30
30
var val
31
31
vm . $watch ( 'a.b.c' , function ( newVal ) {
32
32
val = newVal
33
33
} )
34
34
data . b . c = 'new value!'
35
- assert . strictEqual ( val , data . b . c )
35
+ nextTick ( function ( ) {
36
+ assert . strictEqual ( val , data . b . c )
37
+ done ( )
38
+ } )
36
39
} )
37
40
38
- it ( 'should trigger callback when an object value changes' , function ( ) {
41
+ it ( 'should trigger callback when an object value changes' , function ( done ) {
39
42
var val , subVal , rootVal ,
40
43
target = { c : 'hohoho' }
41
44
vm . $watch ( 'a.b' , function ( newVal ) {
@@ -47,31 +50,45 @@ describe('UNIT: ViewModel', function () {
47
50
vm . $watch ( 'a' , function ( newVal ) {
48
51
rootVal = newVal
49
52
} )
53
+
50
54
data . b = target
51
- assert . strictEqual ( val , target )
52
- assert . strictEqual ( subVal , target . c )
53
- vm . a = 'hehehe'
54
- assert . strictEqual ( rootVal , 'hehehe' )
55
+ nextTick ( function ( ) {
56
+ assert . strictEqual ( val , target )
57
+ assert . strictEqual ( subVal , target . c )
58
+ next ( )
59
+ } )
60
+
61
+ function next ( ) {
62
+ vm . a = 'hehehe'
63
+ nextTick ( function ( ) {
64
+ assert . strictEqual ( rootVal , 'hehehe' )
65
+ done ( )
66
+ } )
67
+ }
68
+
55
69
} )
56
70
57
- it ( 'should trigger callback when an array mutates' , function ( ) {
71
+ it ( 'should trigger callback when an array mutates' , function ( done ) {
58
72
var val , mut
59
73
vm . $watch ( 'b' , function ( array , mutation ) {
60
74
val = array
61
75
mut = mutation
62
76
} )
63
77
arr . push ( 4 )
64
- assert . strictEqual ( val , arr )
65
- assert . strictEqual ( mut . method , 'push' )
66
- assert . strictEqual ( mut . args . length , 1 )
67
- assert . strictEqual ( mut . args [ 0 ] , 4 )
78
+ nextTick ( function ( ) {
79
+ assert . strictEqual ( val , arr )
80
+ assert . strictEqual ( mut . method , 'push' )
81
+ assert . strictEqual ( mut . args . length , 1 )
82
+ assert . strictEqual ( mut . args [ 0 ] , 4 )
83
+ done ( )
84
+ } )
68
85
} )
69
86
70
87
} )
71
88
72
89
describe ( '.$unwatch()' , function ( ) {
73
90
74
- it ( 'should unwatch the stuff' , function ( ) {
91
+ it ( 'should unwatch the stuff' , function ( done ) {
75
92
var triggered = false
76
93
vm . $watch ( 'a.b.c' , function ( ) {
77
94
triggered = true
@@ -87,7 +104,10 @@ describe('UNIT: ViewModel', function () {
87
104
vm . $unwatch ( 'a.b.c' )
88
105
vm . a = { b : { c :123123 } }
89
106
vm . b . push ( 5 )
90
- assert . notOk ( triggered )
107
+ nextTick ( function ( ) {
108
+ assert . notOk ( triggered )
109
+ done ( )
110
+ } )
91
111
} )
92
112
93
113
} )
@@ -477,7 +497,7 @@ describe('UNIT: ViewModel', function () {
477
497
assert . strictEqual ( vm . $data , data )
478
498
} )
479
499
480
- it ( 'should be able to be swapped' , function ( ) {
500
+ it ( 'should be able to be swapped' , function ( done ) {
481
501
var data1 = { a : 1 } ,
482
502
data2 = { a : 2 } ,
483
503
vm = new Vue ( { data : data1 } ) ,
@@ -488,7 +508,10 @@ describe('UNIT: ViewModel', function () {
488
508
} )
489
509
vm . $data = data2
490
510
assert . equal ( vm . a , 2 )
491
- assert . ok ( emittedChange )
511
+ nextTick ( function ( ) {
512
+ assert . ok ( emittedChange )
513
+ done ( )
514
+ } )
492
515
} )
493
516
} )
494
517
0 commit comments