/** * @license * Copyright Google LLC 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 { ɵgetDOM as getDOM } from '@angular/common'; import { ɵglobal as global, ɵRuntimeError as RuntimeError } from '@angular/core'; export class BrowserGetTestability { addToWindow(registry) { global['getAngularTestability'] = (elem, findInAncestors = true) => { const testability = registry.findTestabilityInTree(elem, findInAncestors); if (testability == null) { throw new RuntimeError(5103 /* RuntimeErrorCode.TESTABILITY_NOT_FOUND */, (typeof ngDevMode === 'undefined' || ngDevMode) && 'Could not find testability for element.'); } return testability; }; global['getAllAngularTestabilities'] = () => registry.getAllTestabilities(); global['getAllAngularRootElements'] = () => registry.getAllRootElements(); const whenAllStable = (callback) => { const testabilities = global['getAllAngularTestabilities'](); let count = testabilities.length; let didWork = false; const decrement = function (didWork_) { didWork = didWork || didWork_; count--; if (count == 0) { callback(didWork); } }; testabilities.forEach((testability) => { testability.whenStable(decrement); }); }; if (!global['frameworkStabilizers']) { global['frameworkStabilizers'] = []; } global['frameworkStabilizers'].push(whenAllStable); } findTestabilityInTree(registry, elem, findInAncestors) { if (elem == null) { return null; } const t = registry.getTestability(elem); if (t != null) { return t; } else if (!findInAncestors) { return null; } if (getDOM().isShadowRoot(elem)) { return this.findTestabilityInTree(registry, elem.host, true); } return this.findTestabilityInTree(registry, elem.parentElement, true); } } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdGFiaWxpdHkuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy9wbGF0Zm9ybS1icm93c2VyL3NyYy9icm93c2VyL3Rlc3RhYmlsaXR5LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRztBQUVILE9BQU8sRUFBQyxPQUFPLElBQUksTUFBTSxFQUFDLE1BQU0saUJBQWlCLENBQUM7QUFDbEQsT0F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