Unit Testing private functions in AngularJS Directive
angularjs, angularjs-directive, javascript, unit-testing
Solution
The most common approach is to not test private methods, but instead test the public interfaces that expose their behaviour. This means that your unit test becomes a contract for your public interface.
You've stated that you don't want to expose outside of the directive but of course the other option is to extract this logic into some service `myDirService` and perform your logic there. In that case you'll be able to test in isolation.
Problem
How do I unit test a function that is defined inside a directive like the following `myFunc`? ``` angular.module('myApp') .directive('myDir', [function () { var myFunc = function (arg) { // code in here. }; return { restrict: 'A', scope: { }, link: function (scope, element) { } }; }]); ``` Or how do you define testable directive specific functions that I don't want to expose outside of the directive?