我在自定义指令的模板中有一个嵌套的自定义指令。类似于:
customDirective definition
<custom-directive></custom-directive>customDirective.js
angular.module('example')
.directive('customDirective', function() {
return {
restrict: 'E',
replace: true,
transclude: true,
templateUrl: 'directives/customDirective.html'
link: function(scope, element, attrs) {}
};
});'directives/customDirective.html内部的
<div class="customDirective">
<!-- do a bunch of stuff-->
<!-- but wait, i have an image with a custom-fallback-src directive -->
<img src="image.jpg" custom-fallback-src='newImage.jpg' />
</div>customFallbackSrc.js指令
angular.module('example')
.directive('customFallbackSrc', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
// if image throws an error, use fallback image
element.bind('error', function() {
attrs.$set('src', attrs.customFallbackSrc);
});
}
};
});在我对customDirective的单元测试中,如何正确编译指令以包含任何嵌套指令?
发布于 2015-07-07 03:50:48
如果你想要全面报道,我相信你最好的策略是:
customDirective编写单元测试。但是在这个例子中它是非常稀疏的,所以这有多必要,我不确定。customFallbackSrc编写单元测试。根据提供的示例,您应该对两种情况进行测试:
https://stackoverflow.com/questions/31257682
复制相似问题