Angularjs Testing With Jasmine Unable To Call "angular.mock.module" While Using Angular-mocks.js
I'm trying to get a basic unit test working and am running into an issue using angular-mocks.js. Hopefully this code will explain my situation. describe('peconfigApp', function ()
Solution 1:
I moved the angular-mocks load after the jasmine loads.
<scripttype="text/javascript"src="../lib/angular.min.js"></script><scripttype="text/javascript"src="lib/jasmine.js"></script><scripttype="text/javascript"src="lib/jasmine-html.js"></script><scripttype="text/javascript"src="../lib/angular-mocks.js"></script><scripttype="text/javascript"src="../js/controllers.js"></script><scripttype="text/javascript"src="js/controller-tests.js"></script>
This makes it work. Dumb problem, I must have missed this somewhere while reading through docs and tutorials.
Solution 2:
In order to setup the module
in your unit test you usually would do something like this:
beforeEach(module('peconfigApp'));
As long as your config is set up correctly (to pull in the correct files), that should allow you to then address the module in the test.
The documentation on unit testing is pretty good and worth a couple reads.
Hope this helps.
Solution 3:
I just spent an hour trying to get jasmine to read my controllers, etc. Everything has to be in the exact right order as Chris says.
my index.html for running jasmine:
<htmlng-app="myApp"><body><linkhref="jasmine.css"rel="stylesheet" /><!-- Init Angular --><scriptsrc="../angular.min.js"></script><scriptsrc="../angular-resource.min.js"></script><!-- My code --><scriptsrc="../app/controller.js"></script><scriptsrc="../app/main.js"></script><scriptsrc="../app/service.js"></script><!-- Init Jasmine --><scriptsrc="../jasmine.js"></script><scriptsrc="../jasmine-html.js"></script><scriptsrc="../angular-mocks.js"></script><!-- Insert spec's--><scriptsrc="spec/controller.spec.js"></script><!-- And GO! --><scriptsrc="runner.js"></script><!-- A basic test to check "connectivity" --><divid="container"ng-controller="myCtrl"><h1>Say something... {{data.variablehere}}</h1></div><divid="HTMLReporter"class="jasmine_reporter"></div></body></html>
Post a Comment for "Angularjs Testing With Jasmine Unable To Call "angular.mock.module" While Using Angular-mocks.js"