业力无法找到Javascript控制器

时间:2017-02-26 19:37:56

标签: javascript angularjs karma-jasmine

我试图使用karma和jasmine框架测试我的node.js应用程序。我面临的问题是下面的错误,说我的控制器名称没有注册。我试图做一个简单的测试,看看范围变量是否为空。

错误:控制器名称为' scheduleCtrl'没有注册。

我一直关注这里的教程 链接:https://docs.angularjs.org/guide/controller

scheduleController.js

 angular.module('myApp').controller('scheduleCtrl', 
    ['$scope', '$http', function($scope, $http){

     var indexOfHtml = window.
     $scope.selectedPatient = null;
  }

scheduleController_spec.js

describe("schedule Controller",function(){

    beforeEach(angular.module('myApp'));

    var $controller;
    var $scope = {}; 


    beforeEach(inject(function($rootScope, $controller){
            $scope = $rootScope.$new();
            //this creates a controller for us to use
            $controller('scheduleCtrl', { $scope: $scope});
    }));

            it(" should expect null ", function(){

                    expect($scope.selectedPatient).toEqual(null);

                    }); 

    //});

});

果报config.js

   files: [

            './node_modules/angular/angular.js',
            './node_modules/angular-ui-router/release/angular-ui-router.js',
            './node_modules/angular-mocks/angular-mocks.js',

            './web/static/scripts/app.js',
            './web/static/views/home.html',
            './web/static/scripts/homeController.js',

            './web/static/scripts/scheduleController.js',

            './spec/spec_test.js'
            ],

错误输出

Chrome 56.0.2924 (Mac OS X 10.11.2) schedule Controller  should expect null  FAILED
TypeError: queueableFn.fn.call is not a function
Error: [$controller:ctrlreg] The controller with the name 'scheduleCtrl' is not registered.
http://errors.angularjs.org/1.6.2/$controller/ctrlreg?p0=scheduleCtrl
    at node_modules/angular/angular.js:68:12
    at $controller (node_modules/angular/angular.js:10690:17)
    at node_modules/angular-mocks/angular-mocks.js:2296:14
    at Object.<anonymous> (spec/scheduleController_spec.js:18:3)
    at Object.invoke (node_modules/angular/angular.js:4862:19)
    at Object.WorkFn (node_modules/angular-mocks/angular-mocks.js:3170:20)
Error: Declaration Location
    at window.inject.angular.mock.inject (node_modules/angular-mocks/angular-mocks.js:3133:25)
    at Suite.<anonymous> (spec/scheduleController_spec.js:15:13)
    at spec/scheduleController_spec.js:4:1
Expected undefined to equal null.
    at Object.<anonymous> (spec/scheduleController_spec.js:26:35)

Chrome 56.0.2924(Mac OS X 10.11.2):执行1 of 1(1失败)错误(0.046秒/0.033秒)

1 个答案:

答案 0 :(得分:0)

您可能希望将Karma basePath配置选项设置为正确的目录,其中应解析其他路径(例如files中的路径)。