0

//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?
naga
  • 1
  • 5
  • [Testing directives](https://docs.angularjs.org/guide/unit-testing#testing-directives) – fracz Aug 12 '15 at 21:40
  • I am unable to access scope.myObj inside test. – naga Aug 12 '15 at 22:04
  • [How to Unit Test Isolated Scope Directive in AngularJS](http://stackoverflow.com/questions/17371836/how-to-unit-test-isolated-scope-directive-in-angularjs) – fracz Aug 12 '15 at 22:09

0 Answers0