title: How to avoid errors with unit testing a controller?
body: <p>I am trying to unit test a controller. This is my controller:</p>
  
  <pre><code>app.factory('myService', function ($q) {
      var callMe = function (user) {
          var pr = $q.defer();
          pr.resolve('Hello ' + user);
          return pr.promise;
  
          //$timeout(function(){
          //    pr.resolve('Hello ' + user);
          //    return pr.promise;
          //},4000);
  
      }
      return {callMe: callMe};
  });
  
  
  
  app.controller('myCtrl',function($scope,myService){
      $scope.callService = function(){
          $scope.callMeValue = myService.callMe('lo');
      }
  })
  </code></pre>
  
  <p>This is my test:</p>
  
  <pre><code>beforeEach(
      inject(function (_$rootScope_, $controller, _myService_, _myServiceTimeout_,$q) {
      myService = _myService_;
      myServiceTimeout = _myServiceTimeout_;
      $scope = _$rootScope_.$new();
  
      ctrl = $controller('myCtrl', {
          $scope: $scope,
          someService: someServiceMock
      });
  
      someServiceMock.callMe.andReturn($q.when('Ted'));
  }));
  
  
  it('ctrl test', function () {
      $scope.callService();
      expect(myService.callMe).toHaveBeenCalled();
  });
  </code></pre>
  
  <p>Here are the errors I am getting:</p>
  
  <pre><code>TypeError: someServiceMock.callMe.andReturn is not a function
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>Error: Expected a spy, but got Function.
  </code></pre>
  
  <p>How can I fix this?</p>
  
  <p>plunkr: <a href="http://plnkr.co/edit/EM1blTOlg5fw5wq6OFcr?p=preview" rel="nofollow">http://plnkr.co/edit/EM1blTOlg5fw5wq6OFcr?p=preview</a></p>