@@ -48,6 +48,17 @@ describe('$timeout', function() {
48
48
} ) ) ;
49
49
50
50
51
+ it ( 'should NOT call $apply if no callback function is used' , inject ( function ( $timeout , $rootScope ) {
52
+ var applySpy = spyOn ( $rootScope , '$apply' ) . andCallThrough ( ) ;
53
+
54
+ $timeout ( ) . then ( function ( ) { } ) ;
55
+ expect ( applySpy ) . not . toHaveBeenCalled ( ) ;
56
+
57
+ $timeout . flush ( ) ;
58
+ expect ( applySpy ) . not . toHaveBeenCalled ( ) ;
59
+ } ) ) ;
60
+
61
+
51
62
it ( 'should NOT call $evalAsync or $digest if invokeApply is set to false' ,
52
63
inject ( function ( $timeout , $rootScope ) {
53
64
var evalAsyncSpy = spyOn ( $rootScope , '$evalAsync' ) . andCallThrough ( ) ;
@@ -69,6 +80,10 @@ describe('$timeout', function() {
69
80
$timeout ( noop , 123 ) ;
70
81
expect ( defer . callCount ) . toEqual ( 1 ) ;
71
82
expect ( defer . mostRecentCall . args [ 1 ] ) . toEqual ( 123 ) ;
83
+
84
+ $timeout ( 456 ) ;
85
+ expect ( defer . callCount ) . toEqual ( 2 ) ;
86
+ expect ( defer . mostRecentCall . args [ 1 ] ) . toEqual ( 456 ) ;
72
87
} ) ) ;
73
88
74
89
@@ -81,6 +96,14 @@ describe('$timeout', function() {
81
96
82
97
$timeout . flush ( ) ;
83
98
expect ( log ) . toEqual ( [ 'timeout' , 'promise success: buba' ] ) ;
99
+
100
+ var promise = $timeout ( ) ;
101
+
102
+ promise . then ( function ( value ) { log ( 'promise success' ) ; } , log . fn ( 'promise error' ) ) ;
103
+ expect ( log ) . toEqual ( [ 'timeout' , 'promise success: buba' ] ) ;
104
+
105
+ $timeout . flush ( ) ;
106
+ expect ( log ) . toEqual ( [ 'timeout' , 'promise success: buba' , 'promise success' ] ) ;
84
107
} ) ) ;
85
108
86
109
@@ -165,19 +188,24 @@ describe('$timeout', function() {
165
188
var task1 = jasmine . createSpy ( 'task1' ) ,
166
189
task2 = jasmine . createSpy ( 'task2' ) ,
167
190
task3 = jasmine . createSpy ( 'task3' ) ,
168
- promise1 , promise3 ;
191
+ task4 = jasmine . createSpy ( 'task4' ) ,
192
+ promise1 , promise3 , promise4 ;
169
193
170
194
promise1 = $timeout ( task1 ) ;
171
195
$timeout ( task2 ) ;
172
196
promise3 = $timeout ( task3 , 333 ) ;
197
+ promise4 = $timeout ( 333 ) ;
198
+ promise3 . then ( task4 ) ;
173
199
174
- $timeout . cancel ( promise3 ) ;
175
200
$timeout . cancel ( promise1 ) ;
201
+ $timeout . cancel ( promise3 ) ;
202
+ $timeout . cancel ( promise4 ) ;
176
203
$timeout . flush ( ) ;
177
204
178
205
expect ( task1 ) . not . toHaveBeenCalled ( ) ;
179
206
expect ( task2 ) . toHaveBeenCalledOnce ( ) ;
180
207
expect ( task3 ) . not . toHaveBeenCalled ( ) ;
208
+ expect ( task4 ) . not . toHaveBeenCalled ( ) ;
181
209
} ) ) ;
182
210
183
211
0 commit comments