@@ -121,6 +121,8 @@ angular.mock.$Browser = function($log, $$taskTrackerFactory) {
121
121
* @description
122
122
* Flushes all pending requests and executes the defer callbacks.
123
123
*
124
+ * See {@link ngMock.$flushPendingsTasks} for more info.
125
+ *
124
126
* @param {number= } number of milliseconds to flush. See {@link #defer.now}
125
127
*/
126
128
self . defer . flush = function ( delay ) {
@@ -155,7 +157,9 @@ angular.mock.$Browser = function($log, $$taskTrackerFactory) {
155
157
* Verifies that there are no pending tasks that need to be flushed.
156
158
* You can check for a specific type of tasks only, by specifying a `taskType`.
157
159
*
158
- * @param {string= } taskType - The type task to check for.
160
+ * See {@link $verifyNoPendingsTasks} for more info.
161
+ *
162
+ * @param {string= } taskType - The type tasks to check for.
159
163
*/
160
164
self . defer . verifyNoPendingTasks = function ( taskType ) {
161
165
var pendingTasks = ! taskType
@@ -212,6 +216,72 @@ angular.mock.$Browser.prototype = {
212
216
}
213
217
} ;
214
218
219
+ /**
220
+ * @ngdoc function
221
+ * @name $flushPendingTasks
222
+ *
223
+ * @description
224
+ * Flushes all pending tasks and executes the corresponding callbacks.
225
+ *
226
+ * The types of tasks that are flushed include:
227
+ *
228
+ * - Pending timeouts (via {@link $timeout}).
229
+ * - Pending tasks scheduled via {@link ng.$rootScope.Scope#$applyAsync}.
230
+ * - Pending tasks scheduled via {@link ng.$rootScope.Scope#$evalAsync}.
231
+ * These include tasks scheduled via `$evalAsync()` indirectly (such as {@link $q} promises).
232
+ *
233
+ * <div class="alert alert-info">
234
+ * Periodic tasks scheduled via {@link $interval} use a different queue and are flushed by
235
+ * `$flushPendingTasks()`. Use {@link ngMock.$interval#flush $interval.flush([millis])} instead.
236
+ * </div>
237
+ *
238
+ * @param {number= } delay - The number of milliseconds to flush.
239
+ */
240
+ angular . mock . $FlushPendingTasksProvider = function ( ) {
241
+ this . $get = [
242
+ '$browser' ,
243
+ function ( $browser ) {
244
+ return function $flushPendingTasks ( delay ) {
245
+ return $browser . defer . flush ( delay ) ;
246
+ } ;
247
+ }
248
+ ] ;
249
+ } ;
250
+
251
+ /**
252
+ * @ngdoc function
253
+ * @name $verifyNoPendingTasks
254
+ *
255
+ * @description
256
+ * Verifies that there are no pending tasks that need to be flushed.
257
+ * You can check for a specific type of tasks only, by specifying a `taskType`.
258
+ *
259
+ * Available task types:
260
+ *
261
+ * - `$timeout`: Pending timeouts (via {@link $timeout}).
262
+ * - `$http`: Pending HTTP requests (via {@link $http}).
263
+ * - `$route`: In-progress route transitions (via {@link $route}).
264
+ * - `$applyAsync`: Pending tasks scheduled via {@link ng.$rootScope.Scope#$applyAsync}.
265
+ * - `$evalAsync`: Pending tasks scheduled via {@link ng.$rootScope.Scope#$evalAsync}.
266
+ * These include tasks scheduled via `$evalAsync()` indirectly (such as {@link $q} promises).
267
+ *
268
+ * <div class="alert alert-info">
269
+ * Periodic tasks scheduled via {@link $interval} use a different queue and are not taken into
270
+ * account by `$verifyNoPendingTasks()`.
271
+ * </div>
272
+ *
273
+ * @param {string= } taskType - The type of tasks to check for.
274
+ */
275
+ angular . mock . $VerifyNoPendingTasksProvider = function ( ) {
276
+ this . $get = [
277
+ '$browser' ,
278
+ function ( $browser ) {
279
+ return function $verifyNoPendingTasks ( taskType ) {
280
+ return $browser . defer . verifyNoPendingTasks ( taskType ) ;
281
+ } ;
282
+ }
283
+ ] ;
284
+ } ;
215
285
216
286
/**
217
287
* @ngdoc provider
@@ -2178,6 +2248,13 @@ angular.mock.$TimeoutDecorator = ['$delegate', '$browser', function($delegate, $
2178
2248
* @description
2179
2249
*
2180
2250
* Flushes the queue of pending tasks.
2251
+ * _This method is essentially an alias of {@link ngMock.$flushPendingTasks}._
2252
+ *
2253
+ * <div class="alert alert-warning">
2254
+ * For historical reasons, this method will also flush non-`$timeout` pending tasks, such as
2255
+ * {@link $q} promises and tasks scheduled via {@link ng.$rootScope.Scope#$applyAsync} and
2256
+ * {@link ng.$rootScope.Scope#$evalAsync}.
2257
+ * </div>
2181
2258
*
2182
2259
* @param {number= } delay maximum timeout amount to flush up until
2183
2260
*/
@@ -2194,6 +2271,22 @@ angular.mock.$TimeoutDecorator = ['$delegate', '$browser', function($delegate, $
2194
2271
* @description
2195
2272
*
2196
2273
* Verifies that there are no pending tasks that need to be flushed.
2274
+ * _This method is essentially an alias of {@link ngMock.$verifyNoPendingTasks} (called with no
2275
+ * arguments)._
2276
+ *
2277
+ * <div class="alert alert-warning">
2278
+ * <p>
2279
+ * For historical reasons, this method will also verify non-`$timeout` pending tasks, such as
2280
+ * pending {@link $http} requests, in-progress {@link $route} transitions, unresolved
2281
+ * {@link $q} promises and tasks scheduled via {@link ng.$rootScope.Scope#$applyAsync} and
2282
+ * {@link ng.$rootScope.Scope#$evalAsync}.
2283
+ * </p>
2284
+ * <p>
2285
+ * It is recommended to use {@link ngMock.$verifyNoPendingTasks} instead, which additionally
2286
+ * supports verifying a specific type of tasks. For example, you can verify there are no
2287
+ * pending timeouts with `$verifyNoPendingTasks('$timeout')`.
2288
+ * </p>
2289
+ * </div>
2197
2290
*/
2198
2291
$delegate . verifyNoPendingTasks = function ( ) {
2199
2292
// For historical reasons, `$timeout.verifyNoPendingTasks()` takes all types of pending tasks
@@ -2422,7 +2515,9 @@ angular.module('ngMock', ['ng']).provider({
2422
2515
$log : angular . mock . $LogProvider ,
2423
2516
$interval : angular . mock . $IntervalProvider ,
2424
2517
$rootElement : angular . mock . $RootElementProvider ,
2425
- $componentController : angular . mock . $ComponentControllerProvider
2518
+ $componentController : angular . mock . $ComponentControllerProvider ,
2519
+ $flushPendingTasks : angular . mock . $FlushPendingTasksProvider ,
2520
+ $verifyNoPendingTasks : angular . mock . $VerifyNoPendingTasksProvider
2426
2521
} ) . config ( [ '$provide' , '$compileProvider' , function ( $provide , $compileProvider ) {
2427
2522
$provide . decorator ( '$timeout' , angular . mock . $TimeoutDecorator ) ;
2428
2523
$provide . decorator ( '$$rAF' , angular . mock . $RAFDecorator ) ;
0 commit comments