How to test behavior in the link function of a directive

后端 未结 5 1543
清酒与你
清酒与你 2020-12-23 19:55

In some of my directives, I\'m adding functions to the scope to handle logic specific for the directive. For example:

link: function(scope, element, attrs) {         


        
5条回答
  •  隐瞒了意图╮
    2020-12-23 20:17

     it('should get called on a click', inject(function($rootScope, $compile) {
       var scope = $rootScope.$new();
       element = $compile('
    ')(scope); scope.$digest(); expect(scope.$$childHead.doIt()).toBeDefined(); }));

    Using this $$childHead was the solution for me to the same problem, with this I can cover functions that weren't being called in my tests.

提交回复
热议问题