如何测试销毁范围 [英] How to test on destroy scope
本文介绍了如何测试销毁范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在angularjs中对指令的$ destroy事件进行单元测试?
How to unit testing an $destroy event of a Directive in angularjs?
我的指令中包含代码:
scope.$on('$destroy', function () {
//clean something
});
我的测试代码:
it('on destroy',function(){
scope.$destroy();
scope.$digest();
//expect everything done?
});
任何建议!
推荐答案
您可以从指令模板中选择DOM并获取其范围,然后运行$ destroy().
You can select the DOM from the template of your directive and get the scope of it, then run $destroy().
例如:
您的tpl:
"<div id='tuna'></div>"
您的测试:
it('test on destroy', function(){
var isolateScope = $(element).find('#tuna').eq(0).scope();
isolateScope.$destroy();
})
希望可以帮助您!
这篇关于如何测试销毁范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文