0

I have been stuck on this problem for the past 24 hrs and cannot see what is wrong with my code here. I am getting an injector error from Angular and cannot understand why. Here is my code:

(function (){
  'use strict';
  angular.module('Test', []).factory('stats', factory);

  function factory() {
    return {
      dummy: 'Dummy Text'
    };
  }
})

describe('Test', function() {
  var stats;
  beforeEach(module('Test'));

  beforeEach(inject(function(_stats_) {
    stats = _stats_;
  }));

  it('Should be defined', function() {
    expect(stats).toBeDefined();
  })
})

I have checked my karma.conf.js file and all the files needed are being included in the test. I have another service that belongs to the same module and when I try to inject it instead of 'test' it works as expected.

Any help on this would be greatly appreciated.

Cameron
  • 37
  • 10

1 Answers1

0

You're defining a function, which defines a Test module and adds a service stats, but you never call that function.

The code should be:

(function (){
  ...
})();

Note the additional pair of parentheses used to call the function.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • Thank you so much. I did not know the trailing parentheses were required; I thought those were only for extending classes on the file. – Cameron Jun 17 '16 at 19:35