I have a directive:
app/controllers/battle.js
angular.module('myModule')
.controller('myController',
['$scope',
function($scope){
$scope.sayHello = function(){console.log('hello');};
}])
.directive('myDirective', function(){
return {
templateUrl: '../views/testView.html'
}
});
That directive is called as follows:
app/views/routeOne.html
<my-directive ng-controller='myController'></my-directive>
The directive templateUrl points to a file that looks like:
app/views/testView.html
<div id='testView'>Hello</div>
<div id='eggs'>Here are some eggs.</div>
How do I unit test with karma/jasmine to ensure that the div id in testView.html exists?
Methods tried:
Using ngHtml2Js as per this stackoverflow answer. Reason failed: Unclear on how to access the created module, how the newly created module helps access/query the DOM elements in the testView.html file, unclear what path to use in each of the 4 places testView.html must be pointed to.
Using Html2Js as per this blogpost. Reason failed: Similar to (1).
Accessing the template with jquery.ajax as per this article. Reason failed: angular router prevented me from simply querying straight to the file, though I could access it directly via curl or my browser. Failed on many attempted routes. Probably not only angular router preventing this method from working.
Using $compile as per the angular docs. Reason failed: $compile not found, or, directive not found, or, compiling the directive not returning anything.
Trawling across the internet for how to test an HTML file that's the template for an angular directive yields many different methods, none of which I've managed to make work. I'm happy to use any of the above methods, but I've yet to find a guide that can take me from start to finish in a holistic manner and cover enough of what's happening to actually answer my question. So: how can I test the HTML used by my directive?