jeudi 4 février 2016

Argument 'menuController' is not a function, got undefined error on unit testing my Angular controller

I'm having trouble setting up my unit test project. The first test runs, but trying to set up this one doesn't. The message is this

[ng:areq] Argument 'menuController' is not a function, got undefined

at this line (when debugging)

> menuController = $controller('menuController', {
>             $scope: $scope,
>             appConfig: {}
>         });

This is my code under test:

/// <reference path="./../_references.js" />

(function () {
    'use strict';

    angular
        .module(Main.config.name)
        .controller('menuController', menuController);

    menuController.$inject = ['$state', 'appConfig'];

    function menuController($state, appConfig) {

    }

})();

(I removed all the code from the function menuController, so it would not break on that code in the controller)

And this is the testcode

/// <reference path="../../scripts/_references.js" /> 
'use-strict';

describe('menuController', function () {
    var menuController;
    var $scope;

    beforeEach(function () {
        module(Main.config.name);
    });

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

    menuController = $controller('menuController', {
            $scope: $scope,
            appConfig: {}
        });
    }));



    it('menuController should not be null', function () {
        expect(angular.isObject(menuController)).toBe(true);
        expect(menuController).not.toBe(null);
        expect(menuController).not.toBeUndefined();
    });

});

I have another controller allready running, but that one has no dependencies (and no logic yet):

TEST homeController = $controller('homeController');

and CONTROLLER

/// <reference path="./../_references.js" />


    (function () {
        'use strict';

        angular
            .module(Main.config.name)
            .controller('homeController', homeController);

        function homeController() {

            /* jshint validthis:true */
            var vm = this;

            activate();

            function activate() { }
        }

    })();

Aucun commentaire:

Enregistrer un commentaire