我試圖在現有的角度項目中實現單元測試。對於我添加咕嚕-噶運行單元測試:Karma + Jasmine給出了未定義的函數`controller` error
karma:
unit:
options:
frameworks: ['jasmine'],
singleRun: true,
browsers: ['PhantomJS'],
files: [bower js files + project dev/test js files]
控制器是,
angular.module('app.lol.ctrls', []).controller('LOLCtrl', [
'$scope', '$filter', 'Resource', '$log', function($scope, $filter, Resource, $log) {//some logic}
和測試規範是
describe('Controller: LOLCtrl', function() {
beforeEach(module('app'));
var OrderCtrl;
var scope;
var filter;
var log;
var resource=someResourceWithSomeDataFunc;
beforeEach(inject(function ($controller, $rootScope, $filter, $log) {
scope = $rootScope.$new();
OrderCtrl = $controller('LOLCtrl', {
$scope: scope,
$filter: filter,
Resource: resource,
$log: log
});
}));
it('should have lolVar to be undefined', function() {
expect(scope.lolVar).toBeUndefined();
});
});
當我運行測試,我得到錯誤
PhantomJS 1.9.8 (Linux 0.0.0) Controller: LOLCtrl should have lolVar to be undefined FAILED
Error: [ng:areq] Argument 'LOLCtrl' is not a function, got undefined
http://errors.angularjs.org/1.3.20/ng/areq?p0=LOLCtrl&p1=not%20a%20function%2C%20got%20undefined
undefined
at assertArg ....
我嘗試了像使用angular.mock.module
而不是module
在beforeEach
。另外我還檢查了我是否包含控制器文件。 另外app.lol.ctrls
注入app
本身。我試過beforeEach(module(app.lol.ctrls))
,但是這也給出了同樣的錯誤。 幫助將不勝感激。