title: AngularJS Test that a promise has been called inside a promise
body: <p>I have this method in a service:</p>
  
  <pre><code>this.getCoords = function() {
    var deferred = $q.defer();
  
    geolocation.getLocation().then(function(data) { // line 29 in Karma output
      var coords = _.pick(data.coords, 'latitude', 'longitude');
      return deferred.resolve(coords);
    }, function(reason) {
      return deferred.reject(reason);
    });
  
    return deferred.promise;
  };
  </code></pre>
  
  <p>As <code>geolocation</code> is a module by itself, I just want to test that <code>geolocation.getLocation()</code> promise has indeed been called.</p>
  
  <p>What I've done so far:</p>
  
  <pre><code> ...
  
   geolocationGetLocationSpy = spyOn(geolocation, 'getLocation');
  
   ...
  
   describe('getCoords()', function() {
  
     it('should call geolocation.getLocation()', function() {
       Googlemaps.getCoords(); // line 64 in Karma output
  
       // promise won't get resolved until a digest
       $rootScope.$apply();
  
       expect(geolocationGetLocationSpy).toHaveBeenCalled();
     });
  
   });
  </code></pre>
  
  <p>However I get:</p>
  
  <pre><code>PhantomJS 1.9.2 (Mac OS X) Service: Googlemaps getCoords() should call geolocation.getLocation() FAILED
      TypeError: 'undefined' is not an object (evaluating 'geolocation.getLocation().then')
          at /Users/jviotti/Projects/Temporal/angular/angular-geolocation/app/scripts/services/googleMaps.js:29
          at /Users/jviotti/Projects/Temporal/angular/angular-geolocation/test/spec/services/googleMaps.js:64
  </code></pre>
  
  <p>What else should I do?</p>