title: Testing an AngularJS factory with Karma (Jasmine)
body: <p>I'm struggling with testing an AngularJS factory using Karma + Jasmine.</p>
  
  <p>I am unable to inject my factory to <code>OfficerValidationService</code> variable.</p>
  
  <p>What am i doing wrong?</p>
  
  <p><em>Note: the file is loaded properly</em></p>
  
  <p><strong>Factory:</strong></p>
  
  <pre><code>'use strict';
  
  angular.module('darthvader').factory('OfficerValidationService', [function(){
  
    var OfficerValidationService = {};
  
    OfficerValidationService.something = function() {
      return true;
    };
  
    return OfficerValidationService;
  
  }]);
  </code></pre>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>'use strict';
  
  (function() {
    describe('OfficerValidationService Spec', function() {
  
      var OfficerValidationService;
  
      beforeEach(function() {
        angular.module('darthvader');
      });
  
      beforeEach(module('darthvader', function($provide) {
        $provide.value('OfficerValidationService', OfficerValidationService);
      }));
  
      it('is very true', inject(function(OfficerValidationService){
        alert('=====' + OfficerValidationService + '=====');
        var output = OfficerValidationService.something();
        expect(output).toBeTruthy();
      }));
  
    });
  }());
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>Running "karma:unit" (karma) task
  INFO [karma]: Karma v0.12.17 server started at http://localhost:9876/
  INFO [launcher]: Starting browser PhantomJS
  INFO [PhantomJS 1.9.7 (Mac OS X)]: Connected on socket yc_qTseOCArRtZLAXSTZ with id 97647403
  ALERT: '=====undefined====='
  PhantomJS 1.9.7 (Mac OS X) OfficerValidationService Spec is very true FAILED
      TypeError: 'undefined' is not an object (evaluating 'OfficerValidationService.something')
          at /Users/chuck/Desktop/sandbox/dashboard.darthvader/test/karma/unit/services/officerValidationService.js:25
          at invoke (/Users/chuck/Desktop/sandbox/dashboard.darthvader/public/lib/angular/angular.js:3917)
          at workFn (/Users/chuck/Desktop/sandbox/dashboard.darthvader/public/lib/angular-mocks/angular-mocks.js:2155)
      undefined
  PhantomJS 1.9.7 (Mac OS X): Executed 28 of 28 (1 FAILED) (0.102 secs / 0.131 secs)
  </code></pre>