2
我有一个相当复杂的角度指令,称hy-plugin-window
,我的ng-repeat
块(complete directive code here)内使用:测试角果报:如何设置范围
<div ng-repeat="pluginD in pluginsDisplayed">
<div hy-plugin-window content="pluginD" remove="remove"></div>
</div>
的指令使用的分离范围,至极是双向链接到父的content
成员:
return {
restrict: 'A',
replace: true,
link: linker,
scope: {
content:'=',
}
};
这意味着,在创建时,列表中的每个指令都可以访问它的独特的内容(这是对象的单个成员)并做类似的事情:
scope.statusMessage = 'Loading ' + scope.content.name + '...';
一切正常,但我不知道如何测试它与噶玛。有了这样我希望一个相当普遍的测试手动设置范围的指令内:
'use strict';
describe('Directive: hyPluginWindow', function() {
beforeEach(module('hyacinthHostApp'));
var element, $compile, scope;
beforeEach(inject(function(_$compile_, $rootScope) {
$compile = _$compile_;
scope = $rootScope.$new();
}));
it('should do something', inject(function() {
scope.content = {
name: "testElement",
id: "testElement000",
uiType: "canvas"
};
element = angular.element('<div hy-plugin-window></div>');
element = $compile(element)(scope);
//expect(...);
}));
});
但悲惨的失败:
TypeError: Cannot read property 'name' of undefined
第一次我的指令试图访问其scope.content.name
。
考虑到我是一个测试完整的新手,我错过了什么?
来自Vojta Jina的回答!棒极了。 – James