title: AngularJS Mocking $http returns Error
body: <p>I am having a bit of trouble testing a HTTP POST in AngularJs with Jasmine.</p>
  
  <p>I have a controller that looks like so:-</p>
  
  <pre><code>appControllers.controller("TaskAddController", function ($scope, $http) {
      $scope.task = {};
      $scope.messages = {};
  
      $scope.actions = {
          save : function() {
              $http.post("/ajax/tasks/save", $scope.task)
              .then(function() {
                  $scope.messages.success = true;
                  $scope.task = {};
              });
          }
      };
  });
  </code></pre>
  
  <p>I am testing it like so:-</p>
  
  <pre><code>describe("TaskAddController", function() {
      var createController, scope, $httpBackend;
  
      beforeEach(function () {
          module('appControllers');
  
          scope = {};
  
          inject(function ($injector) {
              $httpBackend = $injector.get("$httpBackend");
          });
  
          inject(function ($controller) {
              createController = function () {
                  return $controller("TaskAddController", { $scope: scope });
              };
          });
      });
  
      afterEach(function () {
          $httpBackend.verifyNoOutstandingExpectation();
          $httpBackend.verifyNoOutstandingRequest();
      });
  
      it("when actions.save is called then should call service", function () {
          var task = {
              title: "Title",
              description: "Description"
          };
  
          $httpBackend.expectPOST("/ajax/tasks/save", task);
          createController();
          scope.task = task;
          scope.actions.save();
          $httpBackend.flush();
      });
  });
  </code></pre>
  
  <p>This causes me to get the following error <code>Error: No pending request to flush !</code></p>
  
  <p>What am I doing wrong?</p>
  
  <p>Thanks.</p>