diff --git a/modules/angular2/src/core/testability/get_testability.dart b/modules/angular2/src/core/testability/get_testability.dart index 450f753da5..d8fbc4757f 100644 --- a/modules/angular2/src/core/testability/get_testability.dart +++ b/modules/angular2/src/core/testability/get_testability.dart @@ -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.'; } diff --git a/modules/angular2/src/core/testability/get_testability.ts b/modules/angular2/src/core/testability/get_testability.ts index f4a23508e0..e8ccf97f58 100644 --- a/modules/angular2/src/core/testability/get_testability.ts +++ b/modules/angular2/src/core/testability/get_testability.ts @@ -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 { var testabilities = registry.getAllTestabilities(); return testabilities.map((testability) => { return new PublicTestability(testability); }); diff --git a/modules/angular2/src/core/testability/testability.ts b/modules/angular2/src/core/testability/testability.ts index 80e14461de..c7bc613407 100644 --- a/modules/angular2/src/core/testability/testability.ts +++ b/modules/angular2/src/core/testability/testability.ts @@ -84,12 +84,14 @@ export class TestabilityRegistry { getAllTestabilities(): List { 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));