title: AngularJS/Karma - unit test function in directive
body: <p>How can I unit test a function inside a directive's link? I tried something like this, but not worked:</p>
  
  <p>directive:</p>
  
  <pre><code>app.directive("hello", function(){
    return {
      link: function(scope){
        scope.hello = function(){
          return "hello";
        };
      }
    };
  });
  </code></pre>
  
  <p>unit test:</p>
  
  <pre><code>describe("Hello directive", function(){
    var compile, scope;
  
    beforeEach(inject(function($compile, $rootScope){
      scope = $rootScope.$new();
      compile = $compile;
    }));
  
    it("should return hello", function(){
      var element = compile("&lt;hello&gt;&lt;/hello&gt;")(scope);
      expect(element.scope.hello()).toBe("hello");
    });
  });
  </code></pre>