我想單元測試以前編寫的指令,對於我的第一個單元測試,我想要做的就是檢查指令範圍內的變量。單元測試指令和isolatedScope不是函數
但是,每當我嘗試在我的html元素上運行方法isolatedScope()
時,我收到錯誤elem.isolatedScope is not a function
。
其中一個奇怪的事情是,當我在我的元素上運行$compile
後,在javascript控制檯上設置了一個斷點後,我就可以打印指令隔離範圍。
試圖將我的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已被棄用(角1.3?),所以它不會工作,除非你使用的是早期版本。 – rrd