How to test behavior in the link function of a directive

后端 未结 5 1560
清酒与你
清酒与你 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:12

    If needed, it's possible to directly unit test the link method of a directive. See the unit tester of the angular-ice module: "testing a directive configuration"

    http://bverbist.github.io/angular-ice/#/unitTester

    example usage: https://github.com/bverbist/angular-ice/blob/master/app/components/icebank/bank-account-number-directive_link_test.js

    In your case you can keep a reference to the scope object you pass to the directive's link method, and then you can directly test the doStuff function on that scope.

提交回复
热议问题