使用茉莉花的角度测试指令链接功能

时间:2015-08-12 16:42:51

标签: angularjs jasmine

// 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
    });
 }
}

现在,如果我需要在茉莉花中对此代码进行测试覆盖,我该怎么做呢。 configurationService是另一个JS中定义的工厂。

html中的myDir用作     

我想写的茉莉花测试是:

it('should fetch data from url link',function(){});
it('should return json data and store in scope.myObj',function(){}

更新1: 我试过这个。

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

});

我也尝试过element.scope()element.children().scope(),没有用。仍未定义。 如果我得到scope.myObj值,那么我想做类似

的事情
expect(scope.myObj).toBe(what should i say?); //or how would I compare such a huge object that is coming in myObj?

0 个答案:

没有答案