I am new to angularJS and unit testing with Karma/Jasmine in general.
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.
Any thoughts?
Aucun commentaire:
Enregistrer un commentaire