title: jasmine - TypeError: Unable to get property 'catch' of undefined or null reference
body: <p>I am trying to create a unit test for a service call in my method. The unit test returns the following error:</p>
  
  <pre><code>TypeError: Unable to get property 'catch' of undefined or null reference
  </code></pre>
  
  <p>Controller method I am testing:</p>
  
  <pre><code>$scope.getAsset = function (id) {
      if ($scope.id != '0') {
          assetFactory.getAsset($scope.id)
          .then(function (response) {
              $scope.asset = response.data;
          })
          .catch(function (error) {
              alertService.add('danger', 'Unable to load asset data: ' + error.statusText + '(' + error.status + '). Please report this error to the application administrator');
          });
      }
  };
  </code></pre>
  
  <p>My unit test is as follows:</p>
  
  <pre><code>it('method getAsset() was called', function () {
      var asset = { AssetId: 'TEST123' };
      var spy = spyOn(assetFactory, 'getAsset').and.callFake(function () {
          return {
              then: function (callback) {
                  return callback(asset);
              }
          };
      });
      // call the controller method
      var result = scope.getAsset();
      // assert that it called the service method. must use a spy
      expect(spy).toHaveBeenCalled();
  });
  </code></pre>
  
  <p>When I remove the ".catch(function (error)" statement from my controller method, the test passes. It appears I have to implement the catch in my spy but I can't figure out how.</p>