@@ -22,16 +22,16 @@ describe('$timeout', function() {
2222 it ( 'should call $apply after each callback is executed' , inject ( function ( $timeout , $rootScope ) {
2323 var applySpy = spyOn ( $rootScope , '$apply' ) . andCallThrough ( ) ;
2424
25- $timeout ( function ( ) { } ) ;
25+ $timeout ( noop ) ;
2626 expect ( applySpy ) . not . toHaveBeenCalled ( ) ;
2727
2828 $timeout . flush ( ) ;
2929 expect ( applySpy ) . toHaveBeenCalledOnce ( ) ;
3030
3131 applySpy . reset ( ) ;
3232
33- $timeout ( function ( ) { } ) ;
34- $timeout ( function ( ) { } ) ;
33+ $timeout ( noop ) ;
34+ $timeout ( noop ) ;
3535 $timeout . flush ( ) ;
3636 expect ( applySpy . callCount ) . toBe ( 2 ) ;
3737 } ) ) ;
@@ -40,7 +40,7 @@ describe('$timeout', function() {
4040 it ( 'should NOT call $apply if skipApply is set to true' , inject ( function ( $timeout , $rootScope ) {
4141 var applySpy = spyOn ( $rootScope , '$apply' ) . andCallThrough ( ) ;
4242
43- $timeout ( function ( ) { } , 12 , false ) ;
43+ $timeout ( noop , 12 , false ) ;
4444 expect ( applySpy ) . not . toHaveBeenCalled ( ) ;
4545
4646 $timeout . flush ( ) ;
@@ -89,8 +89,8 @@ describe('$timeout', function() {
8989 // $browser.defer.cancel is only called on cancel if the deferred object is still referenced
9090 var cancelSpy = spyOn ( $browser . defer , 'cancel' ) . andCallThrough ( ) ;
9191
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 ) ;
9494 expect ( cancelSpy ) . not . toHaveBeenCalled ( ) ;
9595
9696 $timeout . flush ( 0 ) ;
@@ -105,6 +105,28 @@ describe('$timeout', function() {
105105 } ) ) ;
106106
107107
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+
108130 describe ( 'exception handling' , function ( ) {
109131
110132 beforeEach ( module ( function ( $exceptionHandlerProvider ) {
@@ -114,7 +136,7 @@ describe('$timeout', function() {
114136
115137 it ( 'should delegate exception to the $exceptionHandler service' , inject (
116138 function ( $timeout , $exceptionHandler ) {
117- $timeout ( function ( ) { throw "Test Error" ; } ) ;
139+ $timeout ( function ( ) { throw "Test Error" ; } ) ;
118140 expect ( $exceptionHandler . errors ) . toEqual ( [ ] ) ;
119141
120142 $timeout . flush ( ) ;
@@ -126,7 +148,7 @@ describe('$timeout', function() {
126148 function ( $timeout , $rootScope ) {
127149 var applySpy = spyOn ( $rootScope , '$apply' ) . andCallThrough ( ) ;
128150
129- $timeout ( function ( ) { throw "Test Error" ; } ) ;
151+ $timeout ( function ( ) { throw "Test Error" ; } ) ;
130152 expect ( applySpy ) . not . toHaveBeenCalled ( ) ;
131153
132154 $timeout . flush ( ) ;
@@ -145,6 +167,25 @@ describe('$timeout', function() {
145167 } ) ) ;
146168
147169
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+
148189 it ( 'should forget references to relevant deferred even when exception is thrown' ,
149190 inject ( function ( $timeout , $browser ) {
150191 // $browser.defer.cancel is only called on cancel if the deferred object is still referenced
@@ -218,7 +259,7 @@ describe('$timeout', function() {
218259 // $browser.defer.cancel is only called on cancel if the deferred object is still referenced
219260 var cancelSpy = spyOn ( $browser . defer , 'cancel' ) . andCallThrough ( ) ;
220261
221- var promise = $timeout ( function ( ) { } , 0 , false ) ;
262+ var promise = $timeout ( noop , 0 , false ) ;
222263
223264 expect ( cancelSpy ) . not . toHaveBeenCalled ( ) ;
224265 $timeout . cancel ( promise ) ;
0 commit comments