Testing a non-trivial AngularJS app with Jasmine & Karma -
i'm working on non-trivial application, following folder structure:
build (required files such angular.js) gruntfile.js karma.conf.js logs/ node_modules/ src/ - app/ - app.js - module_name/ - module.js - controllers/ - controller1.js - controller2.js - views/ - view1.html - assets/ - 1.jpg - styler.css - components/ (plugged in modules [angular-ui, etc]) - index.html
my controllers each attached parent module. module required in app.js file.
i have tried writing unit tests, seem keep having trouble dependancies, since controller try test requires it's module, module requires one, etc.
my question has few parts:
how go structuring karma.conf.js file include necessary files? part of configuration:
files: [ 'files_to_be_tested.js', ]
using jasmine, how write unit test proper dependancies? example, run following test
javascript
using 'strict' describe('my module', function() { describe('mycontroller', function() { var ctrl, scope; beforeeach(module('mymodule')); beforeeach(inject(function ($rootscope, $controller) { scope = $rootscope.$new(); ctrl = $controller('mycontroller', { $scope: scope }); })); it('should work', function() { // execute functionality }) }) })
but keep getting error: unknown provider: $stateprovider
, think coming loaded module's route configuration.
i'm beginning wonder whether i've been separating out controllers properly?
to answer second question:
unknown provider: $stateprovider
caused ui.router
module not being loaded. solve problem, add beforeeach(module('ui.router'))
the problem arises because controller loading trying inject $state
make sure ui.router
javascript file in files
list in karma.conf.js
or module not available karma.
Comments
Post a Comment