I have an Angular JS directive which has a controller and that controller internally calls many services. How to test this using Karma.
Here is my code structure,
In my
directiveI am displaying the data fromservicewhich internally gets data fromcontroller. It is as below.<div class='tile'><div class="count">{{tileRegistry.tileData.tileCount}}</div></div>
Here tileRegistry is getting data from controller service as below
var commonController = ['$scope','$filter','tileSvc','navSvc','appSetting', function ($scope,$filter, tileSvc,navSvc,applSettig) {
function commonController() {
var tileType = $scope.tile.id;
$scope.tileRegistry=tileSvc.getRegistry(tileType);
$scope.limit=6;
}
commonController();
$scope.link = function(){
var url = $scope.tile.uriLink;
applSetting.setpatientListActive(false);
navSvc.navigateToSegment(url, {});
};
}];
- tileSvc is the service called from controller like below
angular module('app').service('tileSvc',['pblmSvc','procSvc','allgSvc', function(pblmSvc,procSvc,allgSvc){ this.getRegistry = function(tileType){ switch(tileType){ case 'ALG': return allgSvc.registry; break; case 'PROB: return pblmSvc.registry; break; default: return null; } }; }]);
please can anyone tell me how I can mock this controller and service in order to test my directive.
Thanks
pass mock json objects to $controller() and override necessary service calls: