This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +7
-2
lines changed
Expand file tree Collapse file tree 2 files changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -70,12 +70,12 @@ function $TimeoutProvider() {
7070 * Cancels a task associated with the `promise`. As a result of this the promise will be
7171 * resolved with a rejection.
7272 *
73- * @param {Promise } promise Promise returned by the `$timeout` function.
73+ * @param {Promise= } promise Promise returned by the `$timeout` function.
7474 * @returns {boolean } Returns `true` if the task hasn't executed yet and was successfully
7575 * canceled.
7676 */
7777 timeout . cancel = function ( promise ) {
78- if ( promise . $$timeoutId in deferreds ) {
78+ if ( promise && promise . $$timeoutId in deferreds ) {
7979 deferreds [ promise . $$timeoutId ] . reject ( 'canceled' ) ;
8080 return $browser . defer . cancel ( promise . $$timeoutId ) ;
8181 }
Original file line number Diff line number Diff line change @@ -142,5 +142,10 @@ describe('$timeout', function() {
142142 expect ( $timeout . cancel ( promise1 ) ) . toBe ( false ) ;
143143 expect ( $timeout . cancel ( promise2 ) ) . toBe ( true ) ;
144144 } ) ) ;
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+ } ) ) ;
145150 } ) ;
146151} ) ;
You can’t perform that action at this time.
0 commit comments