When working with some of my directives, I often add functions to the scope in order to manage specific logic for that directive. An example of this would be:
link: function(scope, element, attrs) {
scope.doStuff = function() {
//perform a series of actions that need testing
}
}
I've been trying to figure out how to properly test these functions. While searching online for guidance on how to test an AngularJS directive, I came across resources primarily focused on testing changes to the element itself. Compiling the directive before each test is an option, but it resets the scope every time - something I'd like to avoid as I want to test the function when properties within the scope change.
Is there a way to access the object returned from the directive definition? This would allow me to directly call the link function and test the behavior of the scope's defined functions. Are there better methods to achieve this?
I'm using Jasmine for my testing procedures, and I prefer setting up my scope within the describe
functions so I can have multiple it
functions for the same scope data.