2017-02-26 41 views
0

我正在嘗試使用業力和茉莉花框架來測試我的node.js應用程序。我面臨的問題是,下面的錯誤,說我的控制器的名稱沒有註冊。我正在嘗試做一個簡單的測試來查看一個範圍變量是否爲空。無法通過karma找到Javascript控制器

錯誤:名稱爲'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) 

鉻56.0.2924(Mac OS X的10.11.2)○:執行1的1(1 FAILED)ERROR(0.046秒/ 0.033秒)

回答

0

您可能需要將Karma basePath配置選項設置爲正確的目錄,其中應該從其中解析其他路徑(如files)中的路徑。

相關問題