angular/angular.js · error · Error
No more pending request to flush !
Error message
No more pending request to flush !
What it means
The count variant of $httpBackend.flush(count, skip, digest) executes exactly `count` responses, splicing one at a time from position `skip`. When the queue runs dry mid-loop — splice returns an empty array — it throws 'No more pending request to flush !', i.e., you asked for more responses than pending requests exist.
Source
Thrown at src/ngMock/angular-mocks.js:1989
*
* If there are no pending requests to flush when the method is called, an exception is thrown (as
* this is typically a sign of programming error).
*
* @param {number=} count - Number of responses to flush. If undefined/null, all pending requests
* (starting after `skip`) will be flushed.
* @param {number=} [skip=0] - Number of pending requests to skip. For example, a value of `5`
* would skip the first 5 pending requests and start flushing from the 6th onwards.
*/
$httpBackend.flush = function(count, skip, digest) {
if (digest !== false) $rootScope.$digest();
skip = skip || 0;
if (skip >= responses.length) throw new Error('No pending request to flush !');
if (angular.isDefined(count) && count !== null) {
while (count--) {
var part = responses.splice(skip, 1);
if (!part.length) throw new Error('No more pending request to flush !');
part[0]();
}
} else {
while (responses.length > skip) {
responses.splice(skip, 1)[0]();
}
}
$httpBackend.verifyNoOutstandingExpectation(digest);
};
/**
* @ngdoc method
* @name $httpBackend#verifyNoOutstandingExpectation
* @description
* Verifies that all of the requests defined via the `expect` api were made. If any of the
* requests were not made, verifyNoOutstandingExpectation throws an exception.
*View on GitHub (pinned to d8f77817eb)
Solutions
- Omit the count and flush everything: $httpBackend.flush() drains all pending responses.
- Bound the count by what is actually pending: $httpBackend.flush(Math.min(n, $http.pendingRequests.length)) when you really need per-response flushing.
- Update the stale count to match the current number of requests issued by the code under test.
Example fix
// before $httpBackend.flush(3); // throws if only 2 requests pending // after $httpBackend.flush(); // drain all pending responses // or, when stepwise flushing is needed: var pending = $http.pendingRequests.length; $httpBackend.flush(Math.min(3, pending));
Defensive patterns
Strategy: validation
Validate before calling
// Bound the flush count by what is actually pending
inject(function($http, $httpBackend) {
var n = Math.min(3, $http.pendingRequests.length);
if (n > 0) $httpBackend.flush(n);
});
// or simply drain everything: $httpBackend.flush(); Prevention
- Avoid hardcoded counts; flush() without arguments drains all pending responses.
- When stepwise flushing is needed, derive the count from $http.pendingRequests.length.
When it happens
Trigger: $httpBackend.flush(3) when only 2 requests are pending; combining skip with a count larger than the remaining responses.length - skip; hardcoded counts going stale after the app code now issues fewer (or already-flushed) requests.
Common situations: A view load that used to fire 3 API calls is refactored to batch them into 1–2, and the test still flushes 3; two backend calls merged into one endpoint; an early flush in the same test already consumed part of the queue before the flush(count) call.
Related errors
- No pending request to flush !
- Unflushed requests: {} {}
- No deferred tasks to be flushed
- No pending animations ready to be closed or flushed
- Unsatisfied requests: {}
AI-assisted analysis of angular/angular.js@d8f77817eb (2026-08-21).
Data as JSON: /api/errors/02e2d42b90e14a64.
Report an issue: GitHub.