title: How to mock a provider
body: <p>My Angular 1.3 application is using the <a href="http://angular-translate.github.io/" rel="noreferrer">angular-translate library</a>. In my Karma tests I'm attempting to mock the <code>$translate</code> provider with a Mock object I have created.</p>
  
  <p>The mock object is called <code>MockTranslate</code> and it belongs to the <code>myMocks</code> module. I'm not including the source for <code>MockTranslate</code> in the question as it's not relevant to the question. </p>
  
  <p>The subject of my test is a controller and I can quite easily mock <code>$translate</code> using the following:</p>
  
  <pre><code>module('myMocks');
  inject(function($controller, MockTranslate) {                                                                                              
    $controller("MyController", {                                                                                                           
      $translate: MockTranslate.create(translations);                                                                                        
    });                                                                                                                                      
  });
  </code></pre>
  
  <p>The above mocking works, however my preference would be to mock the provider using the <code>angular.mock.module</code> with something like:</p>
  
  <pre><code>module('myMocks');
  module("myModule", function($provide) {                                                                                                    
    $provide.provider("$translate", function(MockTranslate) {                                                                              
      return MockTranslate.create(translations);                                                                                      
    });                                                                                                                                      
  });
  </code></pre>
  
  <p>But I get the following error when I run my tests:</p>
  
  <p><code>Error: [$injector:modulerr] Failed to instantiate module function ($provide) due to: Error: [$injector:unpr] Unknown provider: MockTranslate</code></p>
  
  <p>How do I mock a provider using <code>angular.mock.module</code>?</p>