The 'controllerLogin' argument is undefined and not a function in AngularJs, causing an error during Karma Testing

Hello Brilliant Developers,

I'm currently diving into the world of AngularJs and running into some bumps with basic testing, resulting in pesky errors. I've scoured the web for solutions to no avail. Any assistance you can provide would be greatly appreciated.

Below is the error message:

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

I'm using WebStorm IDE.

Here's my controllerLogin.js file:

'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);

}());

Next up 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");
        });
    });
});

Here's 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'
    ],

Following that 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'});
}]);

Lastly, here's my index.html:

<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 assist me with resolving this issue. Your time and expertise are much appreciated.

Answer №1

Finally, after reaching out to @DanWahlin for assistance, he was able to pinpoint the issue 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"
    ],

Hats off to all the developers who helped out!

Answer №2

Avoid adding the module name to the action value. The module is already loaded, with all controllers accessible through the shared namespace.

action: 'loginController'

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Prevent anchor link click and drag functionality on an HTML page / Swipe through a container containing links

Is there a way to prevent clicking and dragging on a link in a webpage? When you click the left mouse button on a link and drag it, you can unintentionally move the link or open a new tab. I am looking for a way to disable this behavior using JavaScript o ...

Is it possible to start up an Angular Service in a controller without using Dependency Injection?

I've created a service with similar functionality function BroadcastClock($interval, $rootScope){ this.ticker = $interval(function(){ console.log("Tick"); $rootScope.$emit('clockTick'); }, 1000); } function ClockServ ...

Upon submission, the form is processed and 'false' is returned

Does anyone know how I can use ajax to save form data? I am encountering an issue where the page refreshes when all entries are correct. If I input any incorrect data and submit, it displays an error. However, if I then fill in all correct information, it ...

Using JavaScript to place a particular tag at a designated position

I have a string that looks like this: var txtstr='<p>Text 1</p><p>&nbsp;</p><p>Text &nbsp;2</p><p>&nbsp;</p><p>Text 3&nbsp;</p>'; I have an <img src=..../> tag and ...

Pattern for Regular Expression to extract working hours string

I am currently developing a python library designed to parse various types of working hours string inputs and output them in a standardized format. I have encountered a challenge with the following scenario: Specifically, my regular expression should be c ...

Angular application does not have scrollTop set

In my HTML, I have a div identified by the name #target. <div class="col-md-10 col-xs-10"> <div class="quantity-buttons" #target> .... When referencing this div in my TypeScript code, I use the following: @ViewChild('target& ...

Interactions with keys and mouse movements

As I work on my Three.js demo (though I aim for the same functionality across any library), I find myself overwhelmed by the abundance of answers that involve jQuery or other libraries when it comes to user input and events. Being new to this, I prefer st ...

How to Use Angular 8 to Filter an Array of Objects Based on Numeric Values

Can the list be filtered based on the value of iseidaCcaa.id? var centers = [ { id: 2, nombre: "Centro 2", iseidaCcaa: { id: 1, }, }, { id: 3, nombre: "Centro 3", iseidaCcaa: { id: 1, }, }, { id: 1 ...

Error encountered in React V16.7: The function is not valid and cannot be executed

import React, { useContext } from 'react'; The useContext function is returning undefined. Error Details: Uncaught (in promise) TypeError: Object(...) is not a function Error occurred when processing: const context = useContext(UserCon ...

Experiencing Issues with File Downloading on Express Server with Axios and Js-File-Download Library

I developed a feature on my express server that allows users to download a file easily. app.post("/download", (req, res) => { let file_name = req.body.name; res.download(path.join(__dirname, `files/${file_name}.mp3`), (err) => { ...

Analyze a designated section and display the top 3 frequently used words

Below is the code snippet provided: <body> <div id="headbox"> <p>Whatever...</p> </div> <div id="feed"> <div> <p>I hate cats</p> </div> <div> <p>I like ...

Error in Firebase Cloud Function: Function did not return the expected Promise or value and instead returned undefined

I've been encountering an issue with my cloud function that triggers on specific database writes (onCreate). It seems to be working fine, but I keep getting an error message stating "Function returned undefined, expected Promise or value" even though ...

Get all inputs with the same text using Vue 3 composition API and a single ref, or access multiple inputs with the

One of the challenges I'm facing is managing multiple instances of a component called InputWithValidation within a form. I need to check if all instances are valid at once. For a single instance of InputWithValidation, I can easily verify its validit ...

simpleCart - Utilizing a modal window for easy input and sending the shopping cart data to PHP in a multidimensional array

Currently, I am working with the simpleCart JavaScript shopping cart, but I have encountered a minor issue. When a customer clicks "checkout," a modal pops up requiring them to enter their contact information. Upon submitting the form, an email is sent to ...

Exploring the intricacies of Node-Craigslist syntax

Greetings! I am currently utilizing the node-craigslist package found at https://github.com/brozeph/node-craigslist and I am in need of assistance with some syntax related to the details method. The documentation provides the following example: client . ...

Selenium webdriver is unable to click on the element at the given point

I am struggling with clicking on an element in my code without encountering the "Element is not clickable at point" error message. I have tried moving to the element before clicking it, but still cannot get it to work properly. Below is a sample of the co ...

How can I invoke a function within a directive-generated HTML element's scope?

I created a custom directive that utilizes element.html() to set the HTML content. Within this HTML code, I would like to be able to invoke functions from the scope where the directive is being used. Here's an example: app.directive('myDirective ...

Is there anyone who can clarify the operations happening within this Three.js StereoEffect code?

Is there anyone knowledgeable in stereo rendering who can provide an explanation of how these functions work together to achieve the VR stereo effect? Information on functions like StereoCamera(), setScissor(), setViewPort() in the three.js library seems s ...

The AudioPlayerStatus module in Discord JS is a powerful tool for managing

Could you explain why this code snippet: client.player.once(AudioPlayerStatus.Idle, () => { console.log(client.playlist); next.run(message, args, client); client.playlist.shift(); return; }); is b ...

Is there a hashing algorithm that produces identical results in both Dart and TypeScript?

I am looking to create a unique identifier for my chat application. (Chat between my Flutter app and Angular web) Below is the code snippet written in Dart... String peerId = widget.peerid; //string ID value String currentUserId = widget.currentId ...