title: Getting Unknown Provider error when injecting a Service into an Angular unit test
body: <p>I'm fairly new to Angular and have reviewed all the similarly related questions on Stack Overflow but none have helped me. I believe I have everything set up correctly but am still getting an 'Unknown Provider' error when attempting to inject a service into a unit test.  I have laid out my code below - hopefully someone can spot an obvious error!</p>
  
  <p>I define my modules in a seperate <em>.js</em> file like this:</p>
  
  <pre><code>angular.module('dashboard.services', []);
  angular.module('dashboard.controllers', []);
  </code></pre>
  
  <p>Here is where I define a service called  EventingService (with logic removed for brevity):</p>
  
  <pre><code>angular.module('dashboard.services').factory('EventingService', [function () {
      //Service logic here
  }]);
  </code></pre>
  
  <p>Here is my controller that uses the EventingService (this all works fine at runtime):</p>
  
  <pre><code>angular.module('dashboard.controllers')
      .controller('Browse', ['$scope', 'EventingService', function ($scope, eventing) {
          //Controller logic here
  }]);
  </code></pre>
  
  <p>Here is my unit test - its the line where I attempt to inject the EventingService that causes an error when I run the unit test:</p>
  
  <pre><code>describe('Browse Controller Tests.', function () {
      beforeEach(function () {
          module('dashboard.services');
          module('dashboard.controllers');
      });
  
      var controller, scope, eventingService;
  
      beforeEach(inject(function ($controller, $rootScope, EventingService) {
          scope = $rootScope.$new();
          eventingService = EventingService
  
          controller = $controller('Browse', {
              $scope: scope,
              eventing: eventingService
          });
      }));
  
  
      it('Expect True to be True', function () {
          expect(true).toBe(true);
      });
  });
  </code></pre>
  
  <p>When I run the test I get this error:</p>
  
  <blockquote>
    <p>Error: Unknown provider: EventingServiceProvider &lt;- EventingService</p>
  </blockquote>
  
  <p>I have ensured that my jasmine specrunner.html file has all the necessary source files (this is an Asp.Net MVC project):</p>
  
  <pre><code>&lt;!-- Include source files here... --&gt;
  @Scripts.Render("~/bundles/jquery")
  &lt;script type="text/javascript" src="@Url.Content("~/Scripts/angular.js")"&gt;&lt;/script&gt;  
  &lt;script type="text/javascript" src="@Url.Content("~/Scripts/angular-mocks.js")"&gt;&lt;/script&gt;                 
  
  &lt;script type="text/javascript" src="@Url.Content("~/App/scripts/app.js")"&gt;&lt;/script&gt;                       &lt;!-- Angular modules defined in here --&gt;
  &lt;script type="text/javascript" src="@Url.Content("~/App/scripts/services/eventing.js")"&gt;&lt;/script&gt;         &lt;!-- My Eventing service defined here --&gt;
  
  
  &lt;script type="text/javascript" src="@Url.Content("~/App/scripts/controllers/browse.js")"&gt;&lt;/script&gt;        &lt;!-- My Browse controller defined here --&gt;
  
  &lt;!-- Include spec files here... --&gt;
  &lt;script type="text/javascript" src="@Url.Content("~/App/tests/browse.js")"&gt;&lt;/script&gt;                      &lt;!-- The actual unit test here --&gt;
  </code></pre>
  
  <p>I just can not fathom why Angular is throwing this error complaining about my EventingService.  My controller works fine at runtime - it's just when I try to test it that I am getting an error so I am curious as to whether I have screwed something up with the mocking/injection.</p>
  
  <p>The Angular help on testing is rubbish so I am stumped at present - any help or suggestions anyone can give would be very appreciated. Thanks.</p>