Reputation: 497
I need to test Angular controler, but i see an error: "Argument 'MainCtrl' is not a function, got undefined".
Can someone help me, i have no idea...
// file karma conf.js
files: [
'bower_components/angularjs/angular.js',
'bower_components/angular-mocks/angular-mocks.js',
'app.js',
'controllers/*.js',
'directives/*.js',
'services/*.js',
'controllers/controllersSpec.js',
],
// app.js
var app = angular.module('app', []);
// controller
angular.module('app').controller('MainCtrl', ['$scope',
function ($scope) {
$scope.thing = 1;
}]);
// controllersSpec.js
describe('MainCtrl', function() {
var controller, scope;
beforeEach(module('app'));
beforeEach(inject(function($controller, $rootScope) {
scope = $rootScope.$new();
controller = $controller('MainCtrl', {
$scope: scope
});
}));
it('should have scope to be defined', function() {
expect(scope).toBeDefined();
});
});
Can someone help me, i have no idea
Upvotes: 3
Views: 738
Reputation: 44889
It looks like the file, where MainCtrl
is defined hasn't been loaded. Check that this file is being included in karma.conf.js
.
Other than this, your test works: http://jsbin.com/miroqomiyo/edit?html,js,output
Upvotes: 1