title: Mock service injected into Angular module run block
body: <p>In my module.run block it is calling a method on a service I have made. When running my tests I want it to reference a mock service instead of the real one which is making http requests. I am currently trying to test a controller, not the actual run block itself - how can I inject the mock service into the run function? I have tried using $provide.factory but it doesn't seem to do anything and is still loading the service as normal.</p>
  
  <p>I am using Jasmine to write my tests.</p>
  
  <p>app.js</p>
  
  <pre><code>angular.module("app")
      .run(function(MyService) {
          MyService.log("starting app");
      });
  </code></pre>
  
  <p>test.js</p>
  
  <pre><code>describe("MyController", function() {
  
      beforeEach(function() {
          module(function ($provide) {
              $provide.factory("MyService", { log: function(){} });
          });
      });
  
      // I want module 'app' to execute its run function using injected value for MyService
      beforeEach(module("app"));
  
      beforeEach(inject(function($controller, $rootScope) {
          MyController = $controller("MyController", { $scope: $rootScope.$new() });
      }));
  
      ...........
  
  });
  </code></pre>