Argument "controllerLogin" is not a function, got undefined - AngularJs, Karma Testing

Hello Genius Developers,

I am currently learning AngularJs and doing some basic tests but keep getting errors. Please help me with this. I searched for answers but couldn't find anything. Your help would be much appreciated.

Below is the error.

 `Error: [ng:areq] Argument 'controllerLogin' is not a function, got undefined

      

I am using WebStrom IDE.

Here is my controllerLogin.js

'use strict';

var loginApp = angular.module('loginApp',[]);

(function() {

    //define this for the minification of javascripts
    var loginScope=['$scope'];
    var loginController = function($scope){
        $scope.hello = "Hello Galaxy";

    };

    loginController.$inject = loginScope;
    angular.module('loginApp').controller('loginController',loginController);

}());

      

Below is my loginSpec.js

'use strict';

describe("app module", function () {

    beforeEach(module("loginApp"));

    describe("controllerLogin", function () {
        var scope,
            controller;

        beforeEach(inject(function ($rootScope, $controller) {
            scope = $rootScope.$new();
            controller = $controller;
        }));

        it("should assign message to hello world", function () {
            controller("controllerLogin", {$scope: scope});
            expect(scope.message).toBe("Hello Galaxy");
        });
    });
});

      

Below is my galaxytest.conf.js

 // list of files / patterns to load in the browser
    files: [
        'public/scripts/angular.js',
        'public/scripts/angular-mocks.js',
        'public/src/app/*.js',
        'public/app.js',
        '**/*.js',
        'test/**/*Spec.js'
    ],

      

Below is my app.js

//Define all the module with no dependencies.
angular.module('loginApp',[]);


//Now Define Main Module of the Application
var galaxyFrontendApp = angular.module('galaxyFrontendApp',['ngRoute','ui.bootstrap','loginApp']);



galaxyFrontendApp.config(['$routeProvider', function($routeProvider) {
  $routeProvider.when('/login', {templateUrl: 'src/app/modules/login/views/viewLogin.html', action: 'loginApp.loginController'});
  $routeProvider.otherwise({redirectTo: '/login'});
}]);

      

and below is my index.js

<body>
        <div ng-view></div>



        <!-- Please refer all the javascript files here -->
        <!-- All the JS files from scripts folder -->
        <script src="scripts/angular.js"></script>
        <script src="scripts/angular-route.js"></script>
        <script src="scripts/ui-bootstrap.js"></script>
        <script src="app.js"></script>

        <!-- All the JS files from App folder -->
        <!-- Module Name - login -->
        <script src="src/app/modules/login/controllerLogin.js"></script>
        <script src="src/app/modules/login/directiveLogin.js"></script>




    </body>

      

Please help me with this. Thanks for your time and effort.

+3


source to share


2 answers


Finally, I was able to get help from @DanWahlin and he figured out the problem. It was with my galaxytest.conf.js file.

   files: [
       "public/scripts/angular.js",
       "public/scripts/angular-mocks.js",
       "public/scripts/ui-bootstrap.js",
       "public/scripts/angular-route.js",
       "public/app.js",
       "public/src/app/modules/login/controllerLogin.js",
       "public/test/*Spec.js"
    ],

      



Thanks to the developers

+3


source


Do not include the module name in the value specified in the action. The module is already loaded and all of its controllers are in a common namespace.



action: 'loginController'

      

0


source







All Articles