@@ -26,16 +26,19 @@ describe('UNIT: ViewModel', function () {
2626
2727 describe ( '.$watch()' , function ( ) {
2828
29- it ( 'should trigger callback when a plain value changes' , function ( ) {
29+ it ( 'should trigger callback when a plain value changes' , function ( done ) {
3030 var val
3131 vm . $watch ( 'a.b.c' , function ( newVal ) {
3232 val = newVal
3333 } )
3434 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+ } )
3639 } )
3740
38- it ( 'should trigger callback when an object value changes' , function ( ) {
41+ it ( 'should trigger callback when an object value changes' , function ( done ) {
3942 var val , subVal , rootVal ,
4043 target = { c : 'hohoho' }
4144 vm . $watch ( 'a.b' , function ( newVal ) {
@@ -47,31 +50,45 @@ describe('UNIT: ViewModel', function () {
4750 vm . $watch ( 'a' , function ( newVal ) {
4851 rootVal = newVal
4952 } )
53+
5054 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+
5569 } )
5670
57- it ( 'should trigger callback when an array mutates' , function ( ) {
71+ it ( 'should trigger callback when an array mutates' , function ( done ) {
5872 var val , mut
5973 vm . $watch ( 'b' , function ( array , mutation ) {
6074 val = array
6175 mut = mutation
6276 } )
6377 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+ } )
6885 } )
6986
7087 } )
7188
7289 describe ( '.$unwatch()' , function ( ) {
7390
74- it ( 'should unwatch the stuff' , function ( ) {
91+ it ( 'should unwatch the stuff' , function ( done ) {
7592 var triggered = false
7693 vm . $watch ( 'a.b.c' , function ( ) {
7794 triggered = true
@@ -87,7 +104,10 @@ describe('UNIT: ViewModel', function () {
87104 vm . $unwatch ( 'a.b.c' )
88105 vm . a = { b : { c :123123 } }
89106 vm . b . push ( 5 )
90- assert . notOk ( triggered )
107+ nextTick ( function ( ) {
108+ assert . notOk ( triggered )
109+ done ( )
110+ } )
91111 } )
92112
93113 } )
@@ -477,7 +497,7 @@ describe('UNIT: ViewModel', function () {
477497 assert . strictEqual ( vm . $data , data )
478498 } )
479499
480- it ( 'should be able to be swapped' , function ( ) {
500+ it ( 'should be able to be swapped' , function ( done ) {
481501 var data1 = { a : 1 } ,
482502 data2 = { a : 2 } ,
483503 vm = new Vue ( { data : data1 } ) ,
@@ -488,7 +508,10 @@ describe('UNIT: ViewModel', function () {
488508 } )
489509 vm . $data = data2
490510 assert . equal ( vm . a , 2 )
491- assert . ok ( emittedChange )
511+ nextTick ( function ( ) {
512+ assert . ok ( emittedChange )
513+ done ( )
514+ } )
492515 } )
493516 } )
494517
0 commit comments