title: Jasmine spy and resolving promises
body: <p>I am testing a controller that uses a service that returns a promise.  I have mocked out a service in my tests and created a <code>spy</code> so that I can test if the service was actually called. </p>
  
  <p>However I keep getting this error</p>
  
  <pre><code>TypeError: 'undefined' is not a function 
      (evaluating 'spyOn(mockService, 'one').andReturn(deferred.promise)')
  </code></pre>
  
  <p>My Test</p>
  
  <pre><code>beforeEach(inject(function($rootScope, $controller, $q) {
    scope = $rootScope.$new();
  
    mockService = {
      one: function(){
        // mock promise
        var deferred = $q.defer();
        deferred.resolve([
          //my array
        ]);
        return deferred.promise;
      },
      two: function(){
        // mock promise
        var deferred = $q.defer();
        deferred.resolve([
          //my data
        ]);
        return deferred.promise;
      }
    }
    var deferred = $q.defer();
    spyOn(mockService, 'one').andReturn(deferred.promise);
  
    controller = $controller('MyCtrl', {
      $scope: scope,
      mockService: mockService
    });
  }));
  
  it('should call mockService service', function(){
    //causes promises to check to see if they are fulfilled
    scope.$digest();
    expect(mockService.one).toHaveBeenCalled();
  });
  </code></pre>