I've just installed Yeoman and created my first project. I'm trying to get my head around unit testing the default angular project that is created by Yo. The project runs fine when I invoke "grunt server", but when I run the unit test "grunt test:unit" I get the error "Argument 'MainCtrl' is not a function, got undefined".
What am i missing to get this test running properly?
Thanks again
-- controller
'use strict';
angular.module('myApp')
.controller('MainCtrl', function ($scope) {
$scope.awesomeThings = [
'HTML5 Boilerplate',
'AngularJS',
'Karma',
'mytest'
];
});
-- unti test
'use strict';
describe('Controller: MainCtrl', function () {
// load the controller's module
beforeEach(module('myApp'));
var MainCtrl,
scope;
// Initialize the controller and a mock scope
beforeEach(inject(function ($controller, $rootScope) {
scope = $rootScope.$new();
MainCtrl = $controller('MainCtrl', {
$scope: scope
});
}));
it('should attach a list of awesomeThings to the scope', function () {
expect(scope.awesomeThings.length).toBe(4);
});
});
If I copy and paste this code it is executed without problems. The error message you're getting indicates that the controller (name) isn't known to the injector. Did you forget to include the controller javascript file in the karma.conf.js?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With