Directives have low level access to the DOM and can be complex. This makes them prone to errors and hard to debug. Therefore, more than the other areas of your application, it is important that directives have a comprehensive range of tests.
Writing unit tests for directives can seem daunting at first but AngularJS provides some nice features to make it as painless as possible and you will reap the benefits when your directives are reliable and maintainable.
AngularJS has a comprehensive set of tests for its built-in directives. They can be found in the
test/ng/directive folder of the AngularJS project (https://github.com/angular/angular.js/tree/master/test/ng/directive/).
The general strategy when testing directives ...