I am trying to test the following directive.
angular.module('myModule.directives', [])
.directive('test', function() {
return {
restrictions: 'E',
scope: {},
transclude: true,
replace: true,
template: '<div><ui><li>a</li></ul></div>'
}
});
In my test:
describe('directives', function () {
var compile,
scope,
test;
beforeEach(module('myModule.directives'));
beforeEach(inject(function ($compile, $rootScope) {
compile = $compile;
scope = $rootScope;
test = angular.element('<test></test>');
compile(test)(scope);
scope.$digest();
it('should render the test directive', function () {
var lis = test.find('li');
console.log(lis.length); // should output 1
});
}));
Test fails and outputs 0. I am curious as to whether compile is actually doing anything. If I replace test with
test = angular.element("<test><li></li></test>");.
Then the 'find' does find the li within the test element, which goes to show that compile is not rendering to
'<div><ui><li>a</li></ul></div>'
as it should. Any ideas? I looked at the following vid for guidance (http://www.youtube.com/watch?v=rB5b67Cg6bc).