title: Injecting a mock service for an angularjs controller test
body: <p>I'm trying to test a controller that depends on a service I built myself.  I'd like to mock this service since the service talks to the DOM.</p>
  
  <p>Here's my current test:</p>
  
  <pre><code>describe('Player Controllers', function () {
  
      beforeEach(function () {
          this.addMatchers({
              toEqualData: function (expected) {
                  return angular.equals(this.actual, expected);
              }
          });
      });
  
      describe('TestPSPlayerModule', function () {
          var $httpBackend, scope, ctrl;
  
          beforeEach(module('PSPlayerModule'));
  
          beforeEach(inject(function (_$httpBackend_, $rootScope, $controller) {
              $httpBackend = _$httpBackend_;
  
              scope = $rootScope.$new();
              ctrl = $controller(PlayerController, { $scope: scope });
          }));
  
          it('should request a clip url from the server when clipClicked is called', function () {
              expect(1).toBe(1);
          });
      });
  
  });
  </code></pre>
  
  <p>My controller looks like this:</p>
  
  <pre><code>w.PlayerController = function ($scope, $http, $window, speedSlider, $location) {
      ...
  }
  </code></pre>
  
  <p>so it's the speedSlider I want to mock.</p>
  
  <p>I had the idea to use a module I created in my test code that could provide a faked implementation of the speed slider, so I added the following to the top of the test.js file:</p>
  
  <pre><code>module('TestPSPlayerModule', []).factory('speedSlider', function () {
      return = {
         ...
      };
  });
  </code></pre>
  
  <p>and then list that module in the beforeEach() call instead of the concrete one, but if I do that I get the following error:</p>
  
  <pre><code>Injector already created, can not register a module!
  </code></pre>
  
  <p>So I figure there must be a better way for me to provide a mock implementation of one of my services.  Something I can perhaps use sinon.js for....</p>