feat(testability): option to disable tree walking

This commit is contained in:
Michael Goderbauer 2015-08-11 22:34:59 -07:00 committed by Hank Duan
parent ed25a29cc8
commit 8f5360c387
3 changed files with 14 additions and 10 deletions

View File

@ -91,8 +91,9 @@ class PublicTestability implements _JsObjectProxyable {
class GetTestability {
static addToWindow(TestabilityRegistry registry) {
js.context['getAngularTestability'] = _jsify((Element elem) {
Testability testability = registry.findTestabilityInTree(elem);
js.context['getAngularTestability'] = _jsify((Element elem,
[bool findInAncestors = true]) {
Testability testability = registry.findTestabilityInTree(elem, findInAncestors);
if (testability == null) {
throw 'Could not find testability for element.';
}

View File

@ -15,14 +15,15 @@ class PublicTestability {
export class GetTestability {
static addToWindow(registry: TestabilityRegistry) {
global.getAngularTestability = function(elem: Element): PublicTestability {
var testability = registry.findTestabilityInTree(elem);
global.getAngularTestability = function(elem: Element, findInAncestors: boolean = true):
PublicTestability {
var testability = registry.findTestabilityInTree(elem, findInAncestors);
if (testability == null) {
throw new Error('Could not find testability for element.');
}
return new PublicTestability(testability);
};
if (testability == null) {
throw new Error('Could not find testability for element.');
}
return new PublicTestability(testability);
};
global.getAllAngularTestabilities = function(): List<PublicTestability> {
var testabilities = registry.getAllTestabilities();
return testabilities.map((testability) => { return new PublicTestability(testability); });

View File

@ -84,12 +84,14 @@ export class TestabilityRegistry {
getAllTestabilities(): List<Testability> { return MapWrapper.values(this._applications); }
findTestabilityInTree(elem: Node): Testability {
findTestabilityInTree(elem: Node, findInAncestors: boolean = true): Testability {
if (elem == null) {
return null;
}
if (this._applications.has(elem)) {
return this._applications.get(elem);
} else if (!findInAncestors) {
return null;
}
if (DOM.isShadowRoot(elem)) {
return this.findTestabilityInTree(DOM.getHost(elem));