| 18 | import {RuntimeErrorCode} from '../errors'; |
| 19 | |
| 20 | export class BrowserGetTestability implements GetTestability { |
| 21 | addToWindow(registry: TestabilityRegistry): void { |
| 22 | global['getAngularTestability'] = (elem: any, findInAncestors: boolean = true) => { |
| 23 | const testability = registry.findTestabilityInTree(elem, findInAncestors); |
| 24 | if (testability == null) { |
| 25 | throw new RuntimeError( |
| 26 | RuntimeErrorCode.TESTABILITY_NOT_FOUND, |
| 27 | (typeof ngDevMode === 'undefined' || ngDevMode) && |
| 28 | 'Could not find testability for element.', |
| 29 | ); |
| 30 | } |
| 31 | return testability; |
| 32 | }; |
| 33 | |
| 34 | global['getAllAngularTestabilities'] = () => registry.getAllTestabilities(); |
| 35 | |
| 36 | global['getAllAngularRootElements'] = () => registry.getAllRootElements(); |
| 37 | |
| 38 | const whenAllStable = (callback: () => void) => { |
| 39 | const testabilities = global['getAllAngularTestabilities']() as Testability[]; |
| 40 | let count = testabilities.length; |
| 41 | const decrement = function () { |
| 42 | count--; |
| 43 | if (count == 0) { |
| 44 | callback(); |
| 45 | } |
| 46 | }; |
| 47 | testabilities.forEach((testability) => { |
| 48 | testability.whenStable(decrement); |
| 49 | }); |
| 50 | }; |
| 51 | |
| 52 | if (!global['frameworkStabilizers']) { |
| 53 | global['frameworkStabilizers'] = []; |
| 54 | } |
| 55 | global['frameworkStabilizers'].push(whenAllStable); |
| 56 | } |
| 57 | |
| 58 | findTestabilityInTree( |
| 59 | registry: TestabilityRegistry, |
| 60 | elem: any, |
| 61 | findInAncestors: boolean, |
| 62 | ): Testability | null { |
| 63 | if (elem == null) { |
| 64 | return null; |
| 65 | } |
| 66 | const t = registry.getTestability(elem); |
| 67 | if (t != null) { |
| 68 | return t; |
| 69 | } else if (!findInAncestors) { |
| 70 | return null; |
| 71 | } |
| 72 | if (getDOM().isShadowRoot(elem)) { |
| 73 | return this.findTestabilityInTree(registry, (<any>elem).host, true); |
| 74 | } |
| 75 | return this.findTestabilityInTree(registry, elem.parentElement, true); |
| 76 | } |
| 77 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…