This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +7
-2
lines changed
2 files changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -70,12 +70,12 @@ function $TimeoutProvider() {
70
70
* Cancels a task associated with the `promise`. As a result of this the promise will be
71
71
* resolved with a rejection.
72
72
*
73
- * @param {Promise } promise Promise returned by the `$timeout` function.
73
+ * @param {Promise= } promise Promise returned by the `$timeout` function.
74
74
* @returns {boolean } Returns `true` if the task hasn't executed yet and was successfully
75
75
* canceled.
76
76
*/
77
77
timeout . cancel = function ( promise ) {
78
- if ( promise . $$timeoutId in deferreds ) {
78
+ if ( promise && promise . $$timeoutId in deferreds ) {
79
79
deferreds [ promise . $$timeoutId ] . reject ( 'canceled' ) ;
80
80
return $browser . defer . cancel ( promise . $$timeoutId ) ;
81
81
}
Original file line number Diff line number Diff line change @@ -142,5 +142,10 @@ describe('$timeout', function() {
142
142
expect ( $timeout . cancel ( promise1 ) ) . toBe ( false ) ;
143
143
expect ( $timeout . cancel ( promise2 ) ) . toBe ( true ) ;
144
144
} ) ) ;
145
+
146
+
147
+ it ( 'should not throw a runtime exception when given an undefined promise' , inject ( function ( $timeout ) {
148
+ expect ( $timeout . cancel ( ) ) . toBe ( false ) ;
149
+ } ) ) ;
145
150
} ) ;
146
151
} ) ;
You can’t perform that action at this time.
0 commit comments