I have a directive that I want to unittest, but I\'m running into the issue that I can\'t access my isolated scope. Here\'s the directive:
&l
I had the same problem. It seems that when calling $compile(element)($scope)
in conjunction with using a templateUrl
, the digest cycle isn't automatically started. So, you need to set it off manually:
it('should work', function() {
var el = $compile(' ')($scope);
$scope.$digest(); // Ensure changes are propagated
console.log('Isolated scope:', el.isolateScope());
el.isolateScope().save();
expect($log.log).toHaveBeenCalled();
});
I'm not sure why the $compile
function doesn't do this for you, but it must be some idiosyncracy with the way that templateUrl
works, as you don't need to make the call to $scope.$digest()
if you use an inline template.