docs(protracor): add a simpler "awaitForAngular" (#10834)

This commit is contained in:
Nico Jansen 2021-12-10 21:00:21 +01:00 committed by GitHub
parent 027ecd80d0
commit 683dc4eeac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -117,7 +117,22 @@ Here's how to polyfill `waitForAngular` function in Playwright Test:
await executeScriptAsync(page, clientSideScripts.waitForAngular, '');
}
```
If you don't want to keep a version protractor around, you can also use this simpler approach using this function (only works for Angular 2+):
```js
async function waitForAngular(page) {
await page.evaluate(async () => {
// @ts-expect-error
if (window.getAllAngularTestabilities) {
// @ts-expect-error
await Promise.all(window.getAllAngularTestabilities().map(whenStable));
// @ts-expect-error
async function whenStable(testability) {
return new Promise((res) => testability.whenStable(res) );
}
}
});
}
```
1. Polyfill usage
```js