title: Mocking custom provider injected into provider when unit testing Angular in Jasmine
body: <p>I'm unit testing a provider in Jasmine, which relies on another provider. There's no configuration associated with this provider. When mocking a provider, I've read you're supposed to use something like</p>
  
  <pre><code>beforeEach(module(function ($provide) {
      mockInjectedProvider = { };
      $provide.value('injected', mockInjectedProvider );
  }));
  </code></pre>
  
  <p>which works fine for me when injecting a custom provider into a service. When injecting them into a provider it doesn't work though. The code doesn't fail, but what gets executed when testing is the actual provider, not the mocked one. Abstracted example below.</p>
  
  <pre><code>var mockInjectedProvider;
  
  beforeEach(function () {
      module('myModule');
  });
  
  beforeEach(module(function ($provide) {
      mockInjectedProvider = {
          myFunc: function() {
              return "testvalue"
              }
          }
      };
      $provide.value('injected', mockInjectedProvider );
  }));
  
  beforeEach(inject(function (_base_) {
      baseProvider = _base_;
  }));
  
  it("injectedProvider should be mocked", function () {
      var resultFromMockedProvider = baseProvider.executeMyFuncFromInjected();
      expect(resultFromMockedProvider).toEqual("testvalue");
  }); // Here instead of using my mock it executes the actual dependency
  </code></pre>
  
  <p>In the <code>$provide.value</code> statement I've tried including both <code>injected</code> and <code>injectedProvider</code>, as well as using <code>$provide.provider</code> and mocking a <code>$get</code> function on it but nothing seems to work. I just can't get it to mock away the actual provider. Abstracted base provider looks like this. </p>
  
  <pre><code>(function (ng, module) {
      module.provider("base",
          ["injectedProvider", function (injectedProvider) {
              this.executeMyFuncFromInjected= function() {
                  return injectedProvider.myFunc(); // let's say this returns "realvalue"
              }
              this.$get = function () {
                  return this;
              };
          }]
      );
  })(window.angular, window.angular.module("myModule"));
  </code></pre>
  
  <p>Everything in my code is working except the Jasmine mocking.</p>