In our project, we use requirejs with angularjs. We have a main application module (app) and module for all services (app-services), module for all controllers (app-controllers), module for all filters (app-filters). Modules app-controllers, app-services etc.. are added as dependencies to main app module.
main application module
var mainAppModule = angular.module('app', [
'ngResource',
'ngSanitize',
'app.controllers',
'app.directives',
'app.services',
'app.filters',
'app.routes'
]);
mainAppModule.run(['$location', '$rootScope', function ($location, $rootScope) {
$rootScope.sayHello = function(name) {
console.log("Hello" + name);
}
}]);
app-services module
define(['angular'], function (angular) {
var module = angular.module('app.services', []);
module.config(['$provide',function($provide){
module._service = module.service;
module._factory = module.factory;
module._value = module.value;
module.service = function( name, constructor ) {
$provide.service( name, constructor );
return( this );
};
module.factory = function( name, factory ) {
$provide.factory( name, factory );
return( this );
};
module.value = function( name, value ) {
$provide.value( name, value );
return( this );
};
}]);
return module;
});
My questions are
a) how can write unit tests (jasmine/karma) for mainAppModule.run ?
b) how can write unit tests for app-services.config?
Any help is greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire