Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReferenceError: inject is not defined

When I run the SpecRunner HTML file I get this error.

Looking around, this is due to angular-mocks.js not being referenced. In my case it is being referenced.

SpecRunner.html:

  <link rel="stylesheet" type="text/css" href="lib/jasmine-1.3.1/jasmine.css">
  <script type="text/javascript" src="lib/jasmine-1.3.1/jasmine.js"></script>
  <script type="text/javascript" src="lib/jasmine-1.3.1/jasmine-html.js"></script>
  <script type="text/javascript" src="lib/angular-mocks.js"></script>

  <!-- include source files here... -->
  <script type="text/javascript" src="../main/static/js/controllers/norm-definitions-controller.js"></script>

When the tests are run, I get this exception: ReferenceError: inject is not defined

I can see that angular-mocks.js is referenced and it's not a caching issue as I can see it using Firebug.

Looking in angular-mocks.js I can see the full reference angular.mock.inject = function() { ... }, I've tried this as a reference too, and get the exception ReferenceError: angular is not defined.

like image 226
BanksySan Avatar asked Mar 27 '13 23:03

BanksySan


2 Answers

You still need angular.js lib. I didn't saw it among your scripts. It should be before angular-mock.js.

like image 133
Caio Cunha Avatar answered Oct 26 '22 04:10

Caio Cunha


For the errors which come while adding karma and jasmine to testing your project, make sure that

  • your angular.js and angular-mocks js files both have same versions.
  • the jasmine version is compatible with angularjs version, refer to jasmine official site to make sure there is no syntax error.
  • refer to test formation on angular js official site to follow unit testing methodologies.

The above steps help avoid most of the common errors.

like image 39
L.Sidhu Avatar answered Oct 26 '22 06:10

L.Sidhu