AngularJS - 单元测试 - 控制器未定义

时间:2015-05-26 08:24:12

标签: angularjs unit-testing karma-jasmine

我的控制器定义如下:

angular.module("rmt.account-info").controller('AccountInfoController', ['$scope', '$rootScope', '$modal', 'AccountInfoServices', 'UserServices', 'Profile',
function ($scope, $rootScope, $modal, AccountInfoServices, UserServices, Profile) {

我正在尝试为此控制器编写单元测试,如下所示:

describe("Account Info Module", function(){
describe("Account Info Controller", function(){
    var scope, ctrl;

    beforeEach(function(){
        module("rmt.account-info");

        var accountInfoMockService = {}, userMockService = {}, mockedProfileFactory = {};
        var fakeModal = 
        {   
            result: {
                then: function(confirmCallback, cancelCallback){
                    this.confirmCallback = confirmCallback;
                    this.cancelCallback = cancelCallback;
                }
            },
            close: function(item){
                this.result.confirmCallback(item);  
            },
            dismiss: function(reason){
                this.result.cancelCallback(reason);
            }
        };

        module(function($provide, $modal){
            $provide.value('AccountInfoServices', accountInfoMockService);
            $provide.value('UserServices', userMockService);
            $provide.value('Profile', mockedProfileFactory);

            spyOn($modal, 'open').and.returnValue(fakeModal);

            return null;
        });
    });

    beforeEach(inject(function(_$rootScope_, _$controller_, _$modal_, _AccountInfoServices_, _UserServices_, _Profile_){
        scope = _$rootScope_.new();
        $rootScope = _$rootScope_;
        $modal = _$modal_;
        AccountInfoServices = _AccountInfoServices_;
        UserServices = _UserServices_;
        Profile = _Profile_;
        ctrl = _$controller_("accountInfoController", {
            $scope              : scope,
            $rootScope          : $rootScope,
            $modal              : $modal,
            AccountInfoServices : AccountInfoServices,
            UserServices        : UserServices,
            Profile             : Profile
        });
    }));

    describe("Initial State", function(){
        it("should instantiate the controller properly", function(){
            expect(ctrl).not.toBeUndefined();
        });
    });

});

describe("Account Info Service", function(){

});
});

请帮助我知道我哪里出错,我的终端出现以下错误:

由于以下原因导致无法实例化模块{0}: {1}

使用Karma作为测试运行器和Jasmine - 测试框架

Console log error

0 个答案:

没有答案