功能的錯誤,我是很新的Angularjs。我有一個單頁應用中的index.html是根page.it包含以下內容
的index.html
//links to other pages
//ng-view
我有一個app.js文件鏈接到index.html的它加載當用戶使用ngRoute點擊index.html中的鏈接時,相應的頁面。
我app.js網頁看起來是這樣的
app.js
'use strict';
angular.module('myApp', [ 'ngRoute', 'ngAnimate', 'ngSanitize',
'ui.bootstrap', 'checklist-model', 'blockUI','isteven-multi-select' ]);
var App = angular.module('myApp');
//ngroute code
現在頁面search_name.html和search_name_controller.js當用戶點擊索引的鏈接之一下載html的
search_name_controller看起來是這樣的。
search_name_controller.js
'use strict';
App.controller('SearchCifCtrl', [ '$scope', '$location', '$uibModal',
'WorkflowService', 'ConstantService', function($scope, $location, $uibModal,
WorkflowService, ConstantService) {
//some code
} ]);
Snce它是一個單頁的應用程序angular.module語句只在app.js文件寫入。它不是寫在任何其他js文件中。現在我想測試search_name_controller.js使用KARMA.I都這樣寫search_name_controller.test.js下面
describe('search_name_controller', function() {
beforeEach(function() {
module('myApp');
});
var $controller;
beforeEach(inject(function(_$controller_){
$controller = _$controller_;
}));
//code to test method
});
雖然我嘗試運行這個測試,我得到的錯誤是「測試代碼$控制器不是一個函數」。我覺得錯誤是因爲angular.module部分沒有在search_name_controller.js文件中定義。當我嘗試添加它時,我可以運行測試。但我不允許對現有代碼進行任何更改。有什麼辦法在我的測試文件可以讀取app.js文件angular.module一部分,即使我寫search_name_controller.js測試場景。
請幫助
請添加在您使用測試用例腳本中的$控制腳本 –