angular/angular.js · error · Error
No pending request to flush !
Error message
No pending request to flush !
What it means
The fake $httpBackend queues one response entry per request actually made against its expectations/definitions; flush([count][, skip][, digest]) executes them. It throws 'No pending request to flush !' when there is nothing to execute from the requested position — responses is empty, or skip >= responses.length — meaning no (more) HTTP request was made by the code under test.
Source
Thrown at src/ngMock/angular-mocks.js:1984
* @description
* Flushes pending requests using the trained responses. Requests are flushed in the order they
* were made, but it is also possible to skip one or more requests (for example to have them
* flushed later). This is useful for simulating scenarios where responses arrive from the server
* in any order.
*
* 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 methodView on GitHub (pinned to d8f77817eb)
Solutions
- Trigger the request first: call the controller/service method (or run the event handler) that performs $http/$resource before flush().
- If the request is gated behind a $timeout or promise chain, run that step ($timeout.flush()) before $httpBackend.flush().
- Guard the call: check $http.pendingRequests.length > 0 before flushing.
- In multi-flush tests, track how many responses remain and use verifyNoOutstandingRequest() to assert the end state instead of flushing blindly.
Example fix
// before
it('loads users', inject(function($httpBackend, $controller) {
$httpBackend.expectGET('/users').respond([]);
$httpBackend.flush(); // throws: no request made yet
var ctrl = $controller('UserListCtrl');
}));
// after
it('loads users', inject(function($httpBackend, $controller) {
$httpBackend.expectGET('/users').respond([]);
var ctrl = $controller('UserListCtrl'); // constructor issues $http.get
$httpBackend.flush();
})); Defensive patterns
Strategy: validation
Validate before calling
// Flush only when requests are actually in flight
inject(function($http, $httpBackend) {
if ($http.pendingRequests.length > 0) {
$httpBackend.flush();
}
}); Prevention
- Call the controller/service method that issues $http before flush().
- If the request is gated behind $timeout/promise steps, flush those first.
- In afterEach use verifyNoOutstandingRequest()/verifyNoOutstandingExpectation() instead of extra flushes.
When it happens
Trigger: Calling $httpBackend.flush() before the code under test performed any $http/$resource call; calling flush twice when the first flush consumed all responses; using flush(count, skip) with skip pointing past the end of the queue.
Common situations: The test forgot to invoke the controller/service function that issues the request; the request only starts inside a callback that has not run yet (e.g., inside a $timeout — flush() digests first but does not run timers); an earlier exception in the test prevented the $http call; all requests were already flushed by a previous flush in a multi-step test.
Related errors
- No more 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/e2a69bfcdca09f60.
Report an issue: GitHub.