I'm trying to implement the unit testing in existing angular project. For that I've added Grunt-Karma
karma:
unit:
options:
frameworks: ['jasmine'],
singleRun: true,
browsers: ['PhantomJS'],
files: [bower js files + project dev/test js files]
Controller is,
angular.module('app.lol.ctrls', []).controller('LOLCtrl', [
'$scope', '$filter', 'Resource', '$log', function($scope, $filter, Resource, $log) {//some logic}
And test spec is
describe('Controller: LOLCtrl', function () {
beforeEach(module('app'));
var OrderCtrl;
var scope;
var filter;
var log;
var resource=someResourceWithSomeDataFunc;
beforeEach(inject(function ($controller, $rootScope, $filter, $log) {
scope = $rootScope.$new();
OrderCtrl = $controller('LOLCtrl', {
$scope: scope,
$filter: filter,
Resource: resource,
$log: log
});
}));
it('should have lolVar to be undefined', function () {
expect(scope.lolVar).toBeUndefined();
});
});
When I run the test, I'm getting error
PhantomJS 1.9.8 (Linux 0.0.0) Controller: LOLCtrl should have lolVar to be undefined FAILED
Error: [ng:areq] Argument 'LOLCtrl' is not a function, got undefined
http://ift.tt/1Tks4Ih
undefined
at assertArg ....
I tried the solutions like using angular.mock.module
instead of module
in beforeEach
. Also I've double checked whether I'm including the controller file. Also the app.lol.ctrls
is injected in app
itself. I tried beforeEach(module(app.lol.ctrls))
, but that too gives same error. Help would be greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire