{"record":{"id":"2ebe21bc24c61f4f","repo":"angular/angular.js","slug":"unflushed-requests","errorCode":null,"errorMessage":"Unflushed requests: {}\n  {}","messagePattern":"Unflushed requests: (.+?)\n  (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/ngMock/angular-mocks.js","lineNumber":2040,"sourceCode":"\n  /**\n   * @ngdoc method\n   * @name $httpBackend#verifyNoOutstandingRequest\n   * @description\n   * Verifies that there are no outstanding requests that need to be flushed.\n   *\n   * Typically, you would call this method following each test case that asserts requests using an\n   * \"afterEach\" clause.\n   *\n   * ```js\n   *   afterEach($httpBackend.verifyNoOutstandingRequest);\n   * ```\n   */\n  $httpBackend.verifyNoOutstandingRequest = function(digest) {\n    if (digest !== false) $rootScope.$digest();\n    if (responses.length) {\n      var unflushedDescriptions = responses.map(function(res) { return res.description; });\n      throw new Error('Unflushed requests: ' + responses.length + '\\n  ' +\n                      unflushedDescriptions.join('\\n  '));\n    }\n  };\n\n\n  /**\n   * @ngdoc method\n   * @name $httpBackend#resetExpectations\n   * @description\n   * Resets all request expectations, but preserves all backend definitions. Typically, you would\n   * call resetExpectations during a multiple-phase test when you want to reuse the same instance of\n   * $httpBackend mock.\n   */\n  $httpBackend.resetExpectations = function() {\n    expectations.length = 0;\n    responses.length = 0;\n  };\n","sourceCodeStart":2022,"sourceCodeEnd":2058,"githubUrl":"https://github.com/angular/angular.js/blob/d8f77817eb5c98dec5317bc3756d1ea1812bcfbe/src/ngMock/angular-mocks.js#L2022-L2058","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Call $httpBackend.flush() at the end of the test (or wherever responses must be delivered) before verification.","If flushing stepwise with flush(count), make sure the counts add up to all pending responses, or finish with a plain flush().","Treat the per-response descriptions in the message as a checklist of which handlers you forgot to flush."],"exampleFix":"// before\nit('saves item', inject(function($httpBackend, ItemService) {\n  $httpBackend.expectPOST('/items').respond(201, {id: 1});\n  ItemService.save({}); // request queued\n  $httpBackend.verifyNoOutstandingRequest(); // throws: 1 unflushed\n}));\n\n// after\nit('saves item', inject(function($httpBackend, ItemService) {\n  $httpBackend.expectPOST('/items').respond(201, {id: 1});\n  ItemService.save({});\n  $httpBackend.flush(); // deliver the response\n  $httpBackend.verifyNoOutstandingRequest();\n}));","handlingStrategy":"validation","validationCode":"// Flush whatever is pending before verifying\ninject(function($http, $httpBackend) {\n  if ($http.pendingRequests.length > 0) {\n    $httpBackend.flush();\n  }\n  $httpBackend.verifyNoOutstandingRequest();\n});","typeGuard":null,"tryCatchPattern":null,"preventionTips":["End every test that issues requests with a $httpBackend.flush().","After flush(count), verify no remainder with verifyNoOutstandingRequest()."],"tags":["angular-mocks","http-backend","flush","testing"],"backgroundTag":"http-mock-responses-not-flushed","analyzedSha":"d8f77817eb5c98dec5317bc3756d1ea1812bcfbe","analyzedAt":"2026-08-21T20:36:31.651Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}