testability.js
2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { setTestabilityGetter } from '@angular/core';
import { getDOM } from '../dom/dom_adapter';
import { global, isPresent } from '../facade/lang';
export var BrowserGetTestability = (function () {
function BrowserGetTestability() {
}
/**
* @return {?}
*/
BrowserGetTestability.init = function () { setTestabilityGetter(new BrowserGetTestability()); };
/**
* @param {?} registry
* @return {?}
*/
BrowserGetTestability.prototype.addToWindow = function (registry) {
global.getAngularTestability = function (elem, findInAncestors) {
if (findInAncestors === void 0) { findInAncestors = true; }
var /** @type {?} */ testability = registry.findTestabilityInTree(elem, findInAncestors);
if (testability == null) {
throw new Error('Could not find testability for element.');
}
return testability;
};
global.getAllAngularTestabilities = function () { return registry.getAllTestabilities(); };
global.getAllAngularRootElements = function () { return registry.getAllRootElements(); };
var /** @type {?} */ whenAllStable = function (callback /** TODO #9100 */) {
var /** @type {?} */ testabilities = global.getAllAngularTestabilities();
var /** @type {?} */ count = testabilities.length;
var /** @type {?} */ didWork = false;
var /** @type {?} */ decrement = function (didWork_ /** TODO #9100 */) {
didWork = didWork || didWork_;
count--;
if (count == 0) {
callback(didWork);
}
};
testabilities.forEach(function (testability /** TODO #9100 */) {
testability.whenStable(decrement);
});
};
if (!global['frameworkStabilizers']) {
global['frameworkStabilizers'] = [];
}
global['frameworkStabilizers'].push(whenAllStable);
};
/**
* @param {?} registry
* @param {?} elem
* @param {?} findInAncestors
* @return {?}
*/
BrowserGetTestability.prototype.findTestabilityInTree = function (registry, elem, findInAncestors) {
if (elem == null) {
return null;
}
var /** @type {?} */ t = registry.getTestability(elem);
if (isPresent(t)) {
return t;
}
else if (!findInAncestors) {
return null;
}
if (getDOM().isShadowRoot(elem)) {
return this.findTestabilityInTree(registry, getDOM().getHost(elem), true);
}
return this.findTestabilityInTree(registry, getDOM().parentElement(elem), true);
};
return BrowserGetTestability;
}());
//# sourceMappingURL=testability.js.map