0

나는 지시문과 같이 있습니다단위 테스트 각도 지시

angular.module('default', []); 

angular.module('default'). 
directive('default', function() 
{ 

return { 
    restrict: 'A', 
    link: function(scope, element, attrs) {  
     element.bind('error', function() {   
     angular.element(this).attr("src", attrs.default); 

}); 

} 

} 
}); 

내가이 지시어에 대한 단위 테스트를 작성하고자합니다. 단위 테스트 작성을 위해 karma-jasmine을 사용하고 있습니다. 어떻게해야합니까? 이 도움이

describe('default directive', function() { 
    it('Should set attribute src to value of attribute default', inject(function ($compile, $rootscope) { 
     var scope = $rootscope; 
     var elem = angular.element('<div default="test"></div>'); 
     elem = $compile(elem)(scope); 
     expect(elem.children(0)[0].getAttribute('src')).toBe('test'); 
    })); 
}); 

희망 :

답변

1

이런 식으로 뭔가있을거야.

+0

안녕하세요. @ 크리스티나에게 감사합니다. 그러나 나는 기대를 따르지 않았다. (elem.children (0) [0] .getAttribute ('src')). toBe ('test'); statement – user3106657

+0

다른 지시어에 외부 HTML 템플릿이 있습니다. 그러한 지침을 테스트하는 방법은? – user3106657

관련 문제