[英]unit testing directive and isolatedScope not a function
我正在嘗試對先前編寫的指令進行單元測試,而對於我的第一個單元測試,我要做的就是檢查指令范圍內的變量。
但是,每次我嘗試在html元素上運行方法isolatedScope()
時,都會收到錯誤elem.isolatedScope is not a function
。
一件奇怪的事是,當我在javascript控制台上對元素運行$compile
之后立即設置斷點時,我能夠打印指令隔離范圍。
嘗試將我的isolatedScope
設置為如下所示的變量,將始終導致錯誤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;
});
});
});
對我可能做錯的事情有任何想法嗎?
它是isolateScope
,而不是isolatedScope
。
隔離范圍和隔離范圍的術語可以互換使用,但是第一個在官方資料來源中是首選的 (它可能是框架作者之一創造的):
我們想要做的是將指令內部的作用域與外部作用域分開,然后將外部作用域映射到指令的內部作用域。 我們可以通過創建隔離范圍來做到這一點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.