@@ -22,16 +22,16 @@ describe('$timeout', function() {
22
22
it ( 'should call $apply after each callback is executed' , inject ( function ( $timeout , $rootScope ) {
23
23
var applySpy = spyOn ( $rootScope , '$apply' ) . andCallThrough ( ) ;
24
24
25
- $timeout ( function ( ) { } ) ;
25
+ $timeout ( noop ) ;
26
26
expect ( applySpy ) . not . toHaveBeenCalled ( ) ;
27
27
28
28
$timeout . flush ( ) ;
29
29
expect ( applySpy ) . toHaveBeenCalledOnce ( ) ;
30
30
31
31
applySpy . reset ( ) ;
32
32
33
- $timeout ( function ( ) { } ) ;
34
- $timeout ( function ( ) { } ) ;
33
+ $timeout ( noop ) ;
34
+ $timeout ( noop ) ;
35
35
$timeout . flush ( ) ;
36
36
expect ( applySpy . callCount ) . toBe ( 2 ) ;
37
37
} ) ) ;
@@ -40,7 +40,7 @@ describe('$timeout', function() {
40
40
it ( 'should NOT call $apply if skipApply is set to true' , inject ( function ( $timeout , $rootScope ) {
41
41
var applySpy = spyOn ( $rootScope , '$apply' ) . andCallThrough ( ) ;
42
42
43
- $timeout ( function ( ) { } , 12 , false ) ;
43
+ $timeout ( noop , 12 , false ) ;
44
44
expect ( applySpy ) . not . toHaveBeenCalled ( ) ;
45
45
46
46
$timeout . flush ( ) ;
@@ -89,8 +89,8 @@ describe('$timeout', function() {
89
89
// $browser.defer.cancel is only called on cancel if the deferred object is still referenced
90
90
var cancelSpy = spyOn ( $browser . defer , 'cancel' ) . andCallThrough ( ) ;
91
91
92
- var promise1 = $timeout ( function ( ) { } , 0 , false ) ;
93
- var promise2 = $timeout ( function ( ) { } , 100 , false ) ;
92
+ var promise1 = $timeout ( noop , 0 , false ) ;
93
+ var promise2 = $timeout ( noop , 100 , false ) ;
94
94
expect ( cancelSpy ) . not . toHaveBeenCalled ( ) ;
95
95
96
96
$timeout . flush ( 0 ) ;
@@ -105,6 +105,28 @@ describe('$timeout', function() {
105
105
} ) ) ;
106
106
107
107
108
+ it ( 'should pass the timeout arguments in the timeout callback' ,
109
+ inject ( function ( $timeout , $browser ) {
110
+ var task1 = jasmine . createSpy ( 'Nappa' ) ,
111
+ task2 = jasmine . createSpy ( 'Vegeta' ) ;
112
+
113
+ $timeout ( task1 , 9000 , true , 'What does' , 'the timeout' , 'say about' , 'its delay level' ) ;
114
+ expect ( $browser . deferredFns . length ) . toBe ( 1 ) ;
115
+
116
+ $timeout ( task2 , 9001 , false , 'It\'s' , 'over' , 9000 ) ;
117
+ expect ( $browser . deferredFns . length ) . toBe ( 2 ) ;
118
+
119
+ $timeout . flush ( 0 ) ;
120
+ expect ( task1 ) . not . toHaveBeenCalled ( ) ;
121
+
122
+ $timeout . flush ( 9000 ) ;
123
+ expect ( task1 ) . toHaveBeenCalledWith ( 'What does' , 'the timeout' , 'say about' , 'its delay level' ) ;
124
+
125
+ $timeout . flush ( 1 ) ;
126
+ expect ( task2 ) . toHaveBeenCalledWith ( 'It\'s' , 'over' , 9000 ) ;
127
+ } ) ) ;
128
+
129
+
108
130
describe ( 'exception handling' , function ( ) {
109
131
110
132
beforeEach ( module ( function ( $exceptionHandlerProvider ) {
@@ -114,7 +136,7 @@ describe('$timeout', function() {
114
136
115
137
it ( 'should delegate exception to the $exceptionHandler service' , inject (
116
138
function ( $timeout , $exceptionHandler ) {
117
- $timeout ( function ( ) { throw "Test Error" ; } ) ;
139
+ $timeout ( function ( ) { throw "Test Error" ; } ) ;
118
140
expect ( $exceptionHandler . errors ) . toEqual ( [ ] ) ;
119
141
120
142
$timeout . flush ( ) ;
@@ -126,7 +148,7 @@ describe('$timeout', function() {
126
148
function ( $timeout , $rootScope ) {
127
149
var applySpy = spyOn ( $rootScope , '$apply' ) . andCallThrough ( ) ;
128
150
129
- $timeout ( function ( ) { throw "Test Error" ; } ) ;
151
+ $timeout ( function ( ) { throw "Test Error" ; } ) ;
130
152
expect ( applySpy ) . not . toHaveBeenCalled ( ) ;
131
153
132
154
$timeout . flush ( ) ;
@@ -145,6 +167,25 @@ describe('$timeout', function() {
145
167
} ) ) ;
146
168
147
169
170
+ it ( 'should pass the timeout arguments in the timeout callback even if an exception is thrown' ,
171
+ inject ( function ( $timeout , log ) {
172
+ var promise1 = $timeout ( function ( arg ) { throw arg ; } , 9000 , true , 'Some Arguments' ) ;
173
+ var promise2 = $timeout ( function ( arg1 , args2 ) { throw arg1 + ' ' + args2 ; } , 9001 , false , 'Are Meant' , 'To Be Thrown' ) ;
174
+
175
+ promise1 . then ( log . fn ( 'success' ) , function ( reason ) { log ( 'error: ' + reason ) ; } ) ;
176
+ promise2 . then ( log . fn ( 'success' ) , function ( reason ) { log ( 'error: ' + reason ) ; } ) ;
177
+
178
+ $timeout . flush ( 0 ) ;
179
+ expect ( log ) . toEqual ( '' ) ;
180
+
181
+ $timeout . flush ( 9000 ) ;
182
+ expect ( log ) . toEqual ( 'error: Some Arguments' ) ;
183
+
184
+ $timeout . flush ( 1 ) ;
185
+ expect ( log ) . toEqual ( 'error: Some Arguments; error: Are Meant To Be Thrown' ) ;
186
+ } ) ) ;
187
+
188
+
148
189
it ( 'should forget references to relevant deferred even when exception is thrown' ,
149
190
inject ( function ( $timeout , $browser ) {
150
191
// $browser.defer.cancel is only called on cancel if the deferred object is still referenced
@@ -218,7 +259,7 @@ describe('$timeout', function() {
218
259
// $browser.defer.cancel is only called on cancel if the deferred object is still referenced
219
260
var cancelSpy = spyOn ( $browser . defer , 'cancel' ) . andCallThrough ( ) ;
220
261
221
- var promise = $timeout ( function ( ) { } , 0 , false ) ;
262
+ var promise = $timeout ( noop , 0 , false ) ;
222
263
223
264
expect ( cancelSpy ) . not . toHaveBeenCalled ( ) ;
224
265
$timeout . cancel ( promise ) ;
0 commit comments