I have a directive that looks like this:
angular.directive('newDirective', ['$compile', function($compile){
return {
link: function(scope, element, attr, controller) {
console.log("newDirective Content:"+$("#sub").html());
}
};
}]);
I tried to do unit test with this:
describe('newDirective Test',function(){
beforeEach(module('app'));
it('Temporary test jquery function', inject(function($compile,$rootScope) {
var element = $compile('<div new-directive><div id="sub">abc</div></div>')($rootScope);
}));
});
When I run the directive normally, I get the output newDirective Content:abc. But when I run unit test, I get log output newDirective Content:undefined.
How can I get jquery function to work in unit test?