title: How can I spy on a mock service AngularJS / Karma?
body: <pre><code>'use strict'
  
  webApp.controller 'NavigationController', [
    '$scope'
    '$rootScope'
    'UserService'
    ($scope, $rootScope, UserService) -&gt;
      $scope.init = -&gt;
        UserService.isAuthenticated().then (authenticated) -&gt;
          $scope.isAuthenticated = authenticated
  
      $scope.init()
  ]
  </code></pre>
  
  <p>I want to write a test to <code>spyOn</code> if <code>isAuthenticated</code> was called from <code>UserService</code>. In my <code>beforeEach</code>, I have:</p>
  
  <pre><code>  beforeEach -&gt;
      module 'webApp'
  
      inject ($injector) -&gt;
        $httpBackend = $injector.get '$httpBackend'
        $q = $injector.get '$q'
        $rootScope = $injector.get '$rootScope'
  
        $scope = $rootScope.$new()
        $controller = $injector.get '$controller'
  
        UserServiceMock =
          isAuthenticated: -&gt;
            deferred = $q.defer()
            deferred.promise
  
  
        controller = $controller 'AboutUsController',
          '$scope': $scope
          '$rootScope': $rootScope
          'UserService': UserServiceMock
  
        $httpBackend.whenGET('/api/v1/session').respond 200
  </code></pre>
  
  <p>Any help would be appreciated.. thanks</p>