title: Angularjs - how to correctly replace service dependency with a mock
body: <p>I'm using yeoman generator created app, and doing my tests in karma.</p>
  
  <p>I have reusable mock objects for every of my service.
  How do i correctly replace specific service dependcy with a mock, so i could then use jasmine to spy upon methods</p>
  
  <p>So far i have done like this:</p>
  
  <p>My service:</p>
  
  <pre><code>angular.module('ql')
    .service('loginService', ['$http','API','authService', function ($http, API, authService) {
      return {
        //service implementation
      }]);
  </code></pre>
  
  <p>Mock of authService:</p>
  
  <pre><code>'use strict';
  //lets mock http auth  service, so it would be spied upon.
  ql.mock.$authServiceMockProvider = function() {
    this.$get = function() {
      var $service = {
        loginConfirmed: function() { }
      };
      return $service;
    };
  };
  
  //and register it.
  angular.module('qlMock').provider({
    $authServiceMock: ql.mock.$authServiceMockProvider
  });
  </code></pre>
  
  <p>And my test:</p>
  
  <pre><code>'use strict';
  
  describe('When i call login method()', function () {
  
    // load the service's module
    beforeEach(module('ql'));
    beforeEach(angular.mock.module('qlMock'));
  
    // instantiate service
    var loginService,
    authService,
    $httpBackend;
    beforeEach(function() {
      // replace auth service with a mock.
      // this seems kind of dirty... is there a bettery way? 
      module(function($provide, $injector){
        authService = $injector.get('$authServiceMockProvider').$get();
        $provide.value('authService', authService);
      });
  
      //actually get the loginService
      /*jshint camelcase: false */
      inject(function(_loginService_, _$httpBackend_) {
        loginService = _loginService_;
        $httpBackend =_$httpBackend_;
      });
  
      //http auth module method, that should be call only on success scenarios
      spyOn(authService, 'loginConfirmed').andCallThrough();
    });
    it('it should do something', function () {
    //actual test logic
    });
  });
  </code></pre>
  
  <p>What i do not like is the line:</p>
  
  <pre><code>authService = $injector.get('$authServiceMockProvider').$get();
  </code></pre>
  
  <p>I would like to simply somehow get the authServiceMock (without getting provider, and calling et method) and then inject it into loginService.</p>
  
  <p>I know i could call my $authServiceMock simply authService, and provide it as a mock, so that it would always override my default implementation, but i do not want to do this.</p>