How to test on destroy scope

后端 未结 4 866
刺人心
刺人心 2021-02-13 19:02

How to unit testing an $destroy event of a Directive in angularjs?

I have the code in my directive:

scope.$on(\'$destroy\', function () {
    //clean som         


        
4条回答
  •  感动是毒
    2021-02-13 19:17

    You can select the DOM from the template of your directive and get the scope of it, then run $destroy().

    Ex:

    your tpl:

    "
    "

    your test:

    it('test on destroy', function(){
      var isolateScope = $(element).find('#tuna').eq(0).scope();
      isolateScope.$destroy();
    })
    

    Hope help you!

提交回复
热议问题