Reputation: 1167
I am trying to unit test a directive that was previously written and for my first unit test all I want to do is check a variable inside the scope of the directive.
However, every time I try to run the method isolatedScope()
on my html element, I receive the error elem.isolatedScope is not a function
.
One of the strange things is, when I set a breakpoint just after I run $compile
on my element, from the javascript console, I am able to print the directives isolated scope.
Trying to set my isolatedScope
to a variable like below, will always result in the error elem.isolatedScope is not a function
.
describe('directive: wikis', function() {
var $scope, elem, isolated;
beforeEach(module('app'));
beforeEach(inject(function(_$compile_, _$rootScope_){
$scope = _$rootScope_.$new();
elem = angular.element('<wikis></wikis>');
elem = _$compile_(elem)($scope);
isolated = elem.isolatedScope()
isolated.$digest();
}));
describe('$scope should be defined', function(){
it('data should be empty object', function() {
expect(isolated.data).to.be.null;
});
});
});
Any idea on what I might be doing wrong?
Upvotes: 0
Views: 61
Reputation: 222513
It is isolateScope
, not isolatedScope
.
Isolate scope and isolated scope terms can be used interchangeably, but the first one is preferred in official sources (it was likely coined by one of the framework authors):
What we want to be able to do is separate the scope inside a directive from the scope outside, and then map the outer scope to a directive's inner scope. We can do this by creating what we call an isolate scope.
Upvotes: 1