title: How to test behavior in the link function of a directive
body: <p>In some of my directives, I'm adding functions to the scope to handle logic specific for the directive. For example:</p>
  
  <pre><code>link: function(scope, element, attrs) {
           scope.doStuff = function() {
              //do a bunch of stuff I want to test
           }        
        }
  </code></pre>
  
  <p>How do I go about testing that function? I googled around for how test a directive, but <a href="https://stackoverflow.com/questions/12755421/how-to-test-angularjs-directives">the things I found</a> were more about testing changes on the element. I can certainly compile my directive before each of my tests, but that would wipe out my scope every time. I want to test the function as properties in my scope changes.</p>
  
  <p>Is there any way to get a hold of the object that is returned from the directive definition? Then I could just call the link function directly and test the behavior of each of the functions defined on the scope. Is there a better way to do all this?</p>
  
  <p>I'm using Jasmine to run my tests, and I'm wanting to my scope setup in the <code>describe</code> functions, so I can have multiple <code>it</code> functions for the same scope data.</p>