{"record":{"id":"a72a611f9cb771e9","repo":"angular/angular.js","slug":"unsatisfied-requests","errorCode":null,"errorMessage":"Unsatisfied requests: {}","messagePattern":"Unsatisfied requests: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/ngMock/angular-mocks.js","lineNumber":2018,"sourceCode":"\n  /**\n   * @ngdoc method\n   * @name $httpBackend#verifyNoOutstandingExpectation\n   * @description\n   * Verifies that all of the requests defined via the `expect` api were made. If any of the\n   * requests were not made, verifyNoOutstandingExpectation throws an exception.\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.verifyNoOutstandingExpectation);\n   * ```\n   */\n  $httpBackend.verifyNoOutstandingExpectation = function(digest) {\n    if (digest !== false) $rootScope.$digest();\n    if (expectations.length) {\n      throw new Error('Unsatisfied requests: ' + expectations.join(', '));\n    }\n  };\n\n\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) {","sourceCodeStart":2000,"sourceCodeEnd":2036,"githubUrl":"https://github.com/angular/angular.js/blob/d8f77817eb5c98dec5317bc3756d1ea1812bcfbe/src/ngMock/angular-mocks.js#L2000-L2036","documentation":"verifyNoOutstandingExpectation() runs a digest and then throws 'Unsatisfied requests: ...' listing every expectation created with expect()/expectGET()/... that no actual request matched. It is the standard afterEach assertion that all expected HTTP calls actually happened (with matching method, URL, and data).","triggerScenarios":"expectGET('/api/x').respond(...) was declared but the code never issued that request; the request used a different method/URL/data so it never matched (which typically surfaces earlier as 'Unexpected request' during flush); the request is conditional (feature flag, guard clause) and the test's inputs took the other branch; the triggering function was never called.","commonSituations":"afterEach($httpBackend.verifyNoOutstandingExpectation) per the ngMock docs; a controller method tested for the success path while the request lives in the error path; URL mismatch from query strings or a missing/extra leading slash; body data not matching because serialization produced a JSON string the expectation does not deep-equal.","solutions":["Invoke the code under test that performs the expected request before verification (often the fix is simply calling the controller/service function).","Align the expectation with the real call: same method, same URL form (query string, leading slash), and matching data.","For calls that may legitimately not happen, use when() (backend definition) instead of expect() (strict expectation).","Read the thrown message — it lists each unsatisfied 'METHOD url' expectation, which tells you exactly which call is missing."],"exampleFix":"// before\nit('saves', inject(function($httpBackend, $controller) {\n  $httpBackend.expectPOST('/items', {name: 'a'}).respond(200);\n  var ctrl = $controller('ItemCtrl'); // constructor does not POST yet\n  $httpBackend.verifyNoOutstandingExpectation(); // throws: POST /items unsatisfied\n}));\n\n// after\nit('saves', inject(function($httpBackend, $controller) {\n  $httpBackend.expectPOST('/items', {name: 'a'}).respond(200);\n  var ctrl = $controller('ItemCtrl');\n  ctrl.save({name: 'a'}); // now the POST is issued\n  $httpBackend.flush();\n  $httpBackend.verifyNoOutstandingExpectation();\n}));","handlingStrategy":"validation","validationCode":"// Centralize the afterEach contract; expectations that MAY not fire should be when() instead\n// beforeEach: $httpBackend.expectGET('/must') for mandatory calls only\nafterEach(function() {\n  $httpBackend.verifyNoOutstandingExpectation();\n  $httpBackend.verifyNoOutstandingRequest();\n});","typeGuard":null,"tryCatchPattern":"// Produce a clearer failure with the spec name plus the unsatisfied list\ntry {\n  $httpBackend.verifyNoOutstandingExpectation();\n} catch (e) {\n  if (/^Unsatisfied requests:/.test(e.message)) {\n    throw new Error(specName + ' never issued:\\n' + e.message);\n  }\n  throw e;\n}","preventionTips":["Invoke the code under test before the afterEach verification runs.","Match method, URL (query strings, leading slash), and body exactly in expectations.","Use when() for optional calls; reserve expect() for calls that must happen."],"tags":["angular-mocks","http-backend","expectations","testing"],"backgroundTag":"expected-request-not-performed","analyzedSha":"d8f77817eb5c98dec5317bc3756d1ea1812bcfbe","analyzedAt":"2026-08-21T20:36:31.651Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}