title: Jasmine - mock spyOn.and.callFake http success error
body: <p>in my controller I have a call to an http service.  This is my controller:</p>
  
  <pre><code>myApp.controller('MyController', function MyController($scope, myData) {
    myData.getItemsByPage(1, 10)
      .success(function (data, status, headers, config) {
          $scope.items = data.items;
      })
      .error(function (data, status, headers, config) {
          var test = 1;
      });
  });
  </code></pre>
  
  <p>This is the Jasmine test:</p>
  
  <pre><code>it('it should return results', function () {
    var results = {
      "items": [
          {"Title": "Star Wars1","Year": "1977"},
          {"Title": "Star Wars2","Year": "1980"},
          {"Title": "Star Wars3","Year": "1983"}]
    };
  
    spyOn(myData, 'getItemsByPage').and.callFake(function (message, success, fail) {
          return {
              success: function (successCallback) {
                  var status = {};
                  var headers = function() {
                      return {
                          'x-pagination': '{"totalCount": 3}'
                      }
                  };
                  var config = {};
  
                  successCallback(results, status, headers, config);
              },
              error: function (fail) {
                  var x = 1;
              }
          }
      });
      $rootScope.$apply();
      $controller('MyController', { $scope: $scope });
  });
  </code></pre>
  
  <p>I am getting the exception
  "TypeError: Unable to get property 'error' of undefined or null reference"</p>