Using html2js is an ugly way to test directive
First of all, the template markup isnât frozen.
It can, and would probably change when the project grows. You still can mock $templateCache and fill it, breaking dependency.
Consider this directive:
angular.module(âsampleDirectivesâ, [âtemplates-mainâ])
.directive(âfourthDirectiveâ, function () {
return {
templateUrl: âdirectives/sampleTemplate.htmlâ
};
});
In your test, you just need to do this:
$templateCache.put(âdirectives/sampleTemplate.htmlâ, âmyFakeContentâ);
You still can test the updated scope, but right now youâre not depending of an evolving file.