angular/angular.js · error · Error

Unflushed requests: {} {}

Error message

Unflushed requests: {}
  {}

What it means

verifyNoOutstandingRequest() runs a digest and throws 'Unflushed requests: N' (with a description line per pending response) when requests were made against the fake backend but their responses were never delivered via $httpBackend.flush(). The test ended leaving the application waiting on responses it will never receive.

Source

Thrown at src/ngMock/angular-mocks.js:2040

  /**
   * @ngdoc method
   * @name $httpBackend#verifyNoOutstandingRequest
   * @description
   * Verifies that there are no outstanding requests that need to be flushed.
   *
   * Typically, you would call this method following each test case that asserts requests using an
   * "afterEach" clause.
   *
   * ```js
   *   afterEach($httpBackend.verifyNoOutstandingRequest);
   * ```
   */
  $httpBackend.verifyNoOutstandingRequest = function(digest) {
    if (digest !== false) $rootScope.$digest();
    if (responses.length) {
      var unflushedDescriptions = responses.map(function(res) { return res.description; });
      throw new Error('Unflushed requests: ' + responses.length + '\n  ' +
                      unflushedDescriptions.join('\n  '));
    }
  };


  /**
   * @ngdoc method
   * @name $httpBackend#resetExpectations
   * @description
   * Resets all request expectations, but preserves all backend definitions. Typically, you would
   * call resetExpectations during a multiple-phase test when you want to reuse the same instance of
   * $httpBackend mock.
   */
  $httpBackend.resetExpectations = function() {
    expectations.length = 0;
    responses.length = 0;
  };

View on GitHub (pinned to d8f77817eb)

Solutions

  1. Call $httpBackend.flush() at the end of the test (or wherever responses must be delivered) before verification.
  2. If flushing stepwise with flush(count), make sure the counts add up to all pending responses, or finish with a plain flush().
  3. Treat the per-response descriptions in the message as a checklist of which handlers you forgot to flush.

Example fix

// before
it('saves item', inject(function($httpBackend, ItemService) {
  $httpBackend.expectPOST('/items').respond(201, {id: 1});
  ItemService.save({}); // request queued
  $httpBackend.verifyNoOutstandingRequest(); // throws: 1 unflushed
}));

// after
it('saves item', inject(function($httpBackend, ItemService) {
  $httpBackend.expectPOST('/items').respond(201, {id: 1});
  ItemService.save({});
  $httpBackend.flush(); // deliver the response
  $httpBackend.verifyNoOutstandingRequest();
}));
Defensive patterns

Strategy: validation

Validate before calling

// Flush whatever is pending before verifying
inject(function($http, $httpBackend) {
  if ($http.pendingRequests.length > 0) {
    $httpBackend.flush();
  }
  $httpBackend.verifyNoOutstandingRequest();
});

Prevention

When it happens

Trigger: A $http/$resource call was made but the test never called $httpBackend.flush(); flush(count) delivered fewer responses than pending because count was smaller than the queue; a request got queued by a digest triggered late in the test (e.g., from afterEach-run code) after the last flush.

Common situations: afterEach($httpBackend.verifyNoOutstandingRequest) catching a forgotten flush; a save() tested through a promise chain where the test asserted only the request call but not the response; partial flushing with an explicit count leaving remainder responses in the queue.

Related errors


AI-assisted analysis of angular/angular.js@d8f77817eb (2026-08-21). Data as JSON: /api/errors/2ebe21bc24c61f4f. Report an issue: GitHub.