Encountered an issue with testing controllers that are loaded dynamically in my AngularJS application. The controllers are written as follows:
angular.module('myApp').controllerProvider.register('DashboardCtrl', [
'$scope', function ($scope) {
$scope.foo = 'bar';
}
]);
The module is initialized like this:
var app = angular.module('myApp', [
'ngRoute',
'ngCookies',
'ngResource',
'ngSanitize',
'ui.router'
]);
app.run([
'$rootScope', '$state', '$stateParams',
function ($rootScope, $state, $stateParams) {
$rootScope.$state = $state;
$rootScope.$stateParams = $stateParams;
}
]);
app.config(function ($stateProvider, $urlRouterProvider, $controllerProvider, $compileProvider, $filterProvider, $provide) {
// Configuration code here
});
Everything seems to be set up correctly based on the lazy loading method outlined here. However, when attempting to run tests, the following error is encountered: Error: [ng:areq] Argument 'DashboardCtrl' is not a function, got undefined.
The test script used is shown below:
describe('Controller: DashboardCtrl', function () {
'use strict';
var DashboardCtrl,
scope;
beforeEach(function () {
// Setup testing environment
});
it('should attach a list of awesomeThings to the scope', function () {
// Test cases go here
});
});
If anyone has any insights or solutions on what might be causing this error during testing, your help would be greatly appreciated. Thank you in advance.