[英]ReferenceError: Can't find variable: xxxService in AngularJS, Karma
I am new to angularJS and unit testing with Karma/Jasmine in general. 我对angularJS和Karma / Jasmine进行单元测试是新手。
I am trying to add unit tests to an already existing application. 我正在尝试将单元测试添加到已经存在的应用程序中。 One of the service looks like the following:
其中一项服务如下所示:
angular.module('fundMetadata').factory('fundMetadataService', [ 'symedUIGridService', 'symEdService', function(symedUIGridService, symEdService) { var $scope; function setCtrl(controller, scope) { ctrl = controller; $scope = scope; } function defaultGridOptions(columns, data) { return (symedUIGridService.defaultGridOptionsGenerator( $scope, ctrl))(columns, data); } function equityOptions() { var options = defaultGridOptions(ctrl.fundMetadataResponse.equityColumns, ctrl.fundMetadataResponse.equityRecords); options.onRegisterApi = undefined; return options; } return { equityOptions: equityOptions, setCtrl: setCtrl } } ]);
Then the following test in karma/jasmine: 然后在业力/茉莉花中进行以下测试:
describe('fundMetadata', function () { beforeEach(module('fundMetadata')); beforeEach(function () { module('fundMetadata'); inject(function (_fundMetadataService_) { fundMetadataService = _fundMetadataService_; }); }); it('should have the functions', function () { expect(angular.Function(fundMetadataService.setCtrl)).toBe(true); }); });
PhantomJS 2.1.1 (Windows 7 0.0.0) fundMetadata should have the functions FAILED forEach@C:/Users/rvendiola/proj/SymbologyEditor/Website/bower_components/angular/angular.js:321:24 loadModules@C:/Users/rvendiola/proj/SymbologyEditor/Website/bower_components/angular/angular.js:4508:12 createInjector@C:/Users/rvendiola/proj/SymbologyEditor/Website/bower_components/angular/angular.js:4430:30 workFn@C:/Users/rvendiola/proj/SymbologyEditor/Website/bower_components/angular-mocks/angular-mocks.js:2922:60 inject@C:/Users/rvendiola/proj/SymbologyEditor/Website/bower_components/angular-mocks/angular-mocks.js:2902:46 C:/Users/rvendiola/proj/SymbologyEditor/Website/t/fundMetadataService.js:7:15 C:/Users/rvendiola/proj/SymbologyEditor/Website/bower_components/angular/angular.js:4548:53 ReferenceError: Can't find variable: fundMetadataService in C:/Users/rvendiola/proj/SymbologyEditor/Website/t/fundMetadataService.js (line 13) C:/Users/rvendiola/proj/SymbologyEditor/Website/t/fundMetadataService.js:13:52
I made a simple test which tests an app.js and worked okay so i think my installations are fine. 我做了一个简单的测试app.js的测试,并且工作正常,所以我认为我的安装很好。
Any thoughts? 有什么想法吗?
Should have the function. 应该具有的功能。 Meaning, the function should be defined
含义,应该定义功能
it('expects setCtrl to be defined', function () {
expect(fundMetadataService.setCtrl).toBeDefined();
});
"angular.Function" is not a " thing " “ angular.Function”不是“ 事物 ”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.