feat(testability): option to disable tree walking
This commit is contained in:
parent
ed25a29cc8
commit
8f5360c387
|
@ -91,8 +91,9 @@ class PublicTestability implements _JsObjectProxyable {
|
||||||
|
|
||||||
class GetTestability {
|
class GetTestability {
|
||||||
static addToWindow(TestabilityRegistry registry) {
|
static addToWindow(TestabilityRegistry registry) {
|
||||||
js.context['getAngularTestability'] = _jsify((Element elem) {
|
js.context['getAngularTestability'] = _jsify((Element elem,
|
||||||
Testability testability = registry.findTestabilityInTree(elem);
|
[bool findInAncestors = true]) {
|
||||||
|
Testability testability = registry.findTestabilityInTree(elem, findInAncestors);
|
||||||
if (testability == null) {
|
if (testability == null) {
|
||||||
throw 'Could not find testability for element.';
|
throw 'Could not find testability for element.';
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,14 +15,15 @@ class PublicTestability {
|
||||||
|
|
||||||
export class GetTestability {
|
export class GetTestability {
|
||||||
static addToWindow(registry: TestabilityRegistry) {
|
static addToWindow(registry: TestabilityRegistry) {
|
||||||
global.getAngularTestability = function(elem: Element): PublicTestability {
|
global.getAngularTestability = function(elem: Element, findInAncestors: boolean = true):
|
||||||
var testability = registry.findTestabilityInTree(elem);
|
PublicTestability {
|
||||||
|
var testability = registry.findTestabilityInTree(elem, findInAncestors);
|
||||||
|
|
||||||
if (testability == null) {
|
if (testability == null) {
|
||||||
throw new Error('Could not find testability for element.');
|
throw new Error('Could not find testability for element.');
|
||||||
}
|
}
|
||||||
return new PublicTestability(testability);
|
return new PublicTestability(testability);
|
||||||
};
|
};
|
||||||
global.getAllAngularTestabilities = function(): List<PublicTestability> {
|
global.getAllAngularTestabilities = function(): List<PublicTestability> {
|
||||||
var testabilities = registry.getAllTestabilities();
|
var testabilities = registry.getAllTestabilities();
|
||||||
return testabilities.map((testability) => { return new PublicTestability(testability); });
|
return testabilities.map((testability) => { return new PublicTestability(testability); });
|
||||||
|
|
|
@ -84,12 +84,14 @@ export class TestabilityRegistry {
|
||||||
|
|
||||||
getAllTestabilities(): List<Testability> { return MapWrapper.values(this._applications); }
|
getAllTestabilities(): List<Testability> { return MapWrapper.values(this._applications); }
|
||||||
|
|
||||||
findTestabilityInTree(elem: Node): Testability {
|
findTestabilityInTree(elem: Node, findInAncestors: boolean = true): Testability {
|
||||||
if (elem == null) {
|
if (elem == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (this._applications.has(elem)) {
|
if (this._applications.has(elem)) {
|
||||||
return this._applications.get(elem);
|
return this._applications.get(elem);
|
||||||
|
} else if (!findInAncestors) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
if (DOM.isShadowRoot(elem)) {
|
if (DOM.isShadowRoot(elem)) {
|
||||||
return this.findTestabilityInTree(DOM.getHost(elem));
|
return this.findTestabilityInTree(DOM.getHost(elem));
|
||||||
|
|
Loading…
Reference in New Issue