//angular directive
directive('myDir', function(ConfigurationService) {
return {
controller: 'myDirController',
scope: {},
restrict: 'E',
templateUrl: '../app/template/myDir.html',
link: function(scope, element, attributes) {
myService.init(attributes).then(function(jsonObj){ // need to cover test
scope.myObj = jsonObj; //jsonObj has a json and need to cover test
});
}
}
Now, if I need to do test coverage for this code in jasmine, how can I do that. configurationService is a factory defined in another JS.
The myDir in html is used as
The jasmine test I want to write is:
it('should fetch data from url link',function(){});
it('should return json data and store in scope.myObj',function(){}
update 1: I tried this.
it('should store data in scope object',function(){
var element = $compile('<my-dir url="/Json/in/local/myJson.json"></my-dir>')($scope), iscope;
$rootScope.$digest();
iscope = element.isolateScope();
console.log("scope.myObj: ",iscope.myObj); // getting undefined
});
I also, tried, element.scope()
and element.children().scope()
, no use. still getting undefined.
If i get scope.myObj value then I want to do something like
expect(scope.myObj).toBe(what should i say?); //or how would I compare such a huge object that is coming in myObj?