@@ -1328,17 +1328,49 @@ function MockXhr() {
1328
1328
* @description
1329
1329
*
1330
1330
* This service is just a simple decorator for {@link ng.$timeout $timeout} service
1331
- * that adds a "flush" method .
1332
- */
1331
+ * that adds a "flush" and "verifyNoPendingTasks" methods .
1332
+ */
1333
1333
1334
- /**
1335
- * @ngdoc method
1336
- * @name ngMock.$timeout#flush
1337
- * @methodOf ngMock.$timeout
1338
- * @description
1339
- *
1340
- * Flushes the queue of pending tasks.
1341
- */
1334
+ angular . mock . $TimeoutDecorator = function ( $delegate , $browser ) {
1335
+
1336
+ /**
1337
+ * @ngdoc method
1338
+ * @name ngMock.$timeout#flush
1339
+ * @methodOf ngMock.$timeout
1340
+ * @description
1341
+ *
1342
+ * Flushes the queue of pending tasks.
1343
+ */
1344
+ $delegate . flush = function ( ) {
1345
+ $browser . defer . flush ( ) ;
1346
+ } ;
1347
+
1348
+ /**
1349
+ * @ngdoc method
1350
+ * @name ngMock.$timeout#verifyNoPendingTasks
1351
+ * @methodOf ngMock.$timeout
1352
+ * @description
1353
+ *
1354
+ * Verifies that there are no pending tasks that need to be flushed.
1355
+ */
1356
+ $delegate . verifyNoPendingTasks = function ( ) {
1357
+ if ( $browser . deferredFns . length ) {
1358
+ throw Error ( 'Deferred tasks to flush (' + $browser . deferredFns . length + '): ' +
1359
+ formatPendingTasksAsString ( $browser . deferredFns ) ) ;
1360
+ }
1361
+ } ;
1362
+
1363
+ function formatPendingTasksAsString ( tasks ) {
1364
+ var result = [ ] ;
1365
+ angular . forEach ( tasks , function ( task ) {
1366
+ result . push ( '{id: ' + task . id + ', ' + 'time: ' + task . time + '}' ) ;
1367
+ } ) ;
1368
+
1369
+ return result . join ( ', ' ) ;
1370
+ }
1371
+
1372
+ return $delegate ;
1373
+ } ;
1342
1374
1343
1375
/**
1344
1376
*
@@ -1364,15 +1396,9 @@ angular.module('ngMock', ['ng']).provider({
1364
1396
$httpBackend : angular . mock . $HttpBackendProvider ,
1365
1397
$rootElement : angular . mock . $RootElementProvider
1366
1398
} ) . config ( function ( $provide ) {
1367
- $provide . decorator ( '$timeout' , function ( $delegate , $browser ) {
1368
- $delegate . flush = function ( ) {
1369
- $browser . defer . flush ( ) ;
1370
- } ;
1371
- return $delegate ;
1372
- } ) ;
1399
+ $provide . decorator ( '$timeout' , angular . mock . $TimeoutDecorator ) ;
1373
1400
} ) ;
1374
1401
1375
-
1376
1402
/**
1377
1403
* @ngdoc overview
1378
1404
* @name ngMockE2E
0 commit comments