fix: support async functions as an argument for waitForFunction (#5682)

This commit is contained in:
Islam ElHakmi
2020-05-19 09:09:31 +02:00
committed by GitHub
parent e6c22dae05
commit caaf4d2086
3 changed files with 72 additions and 12 deletions

View File

@@ -138,6 +138,22 @@ describe('waittask specs', function () {
await watchdog;
expect(Date.now() - startTime).not.toBeLessThan(polling / 2);
});
it('should poll on interval async', async () => {
const { page } = getTestState();
let success = false;
const startTime = Date.now();
const polling = 100;
const watchdog = page
.waitForFunction(async () => window.__FOO === 'hit', { polling })
.then(() => (success = true));
await page.evaluate(async () => (window.__FOO = 'hit'));
expect(success).toBe(false);
await page.evaluate(async () =>
document.body.appendChild(document.createElement('div'))
);
await watchdog;
expect(Date.now() - startTime).not.toBeLessThan(polling / 2);
});
it('should poll on mutation', async () => {
const { page } = getTestState();
@@ -152,6 +168,22 @@ describe('waittask specs', function () {
);
await watchdog;
});
it('should poll on mutation async', async () => {
const { page } = getTestState();
let success = false;
const watchdog = page
.waitForFunction(async () => window.__FOO === 'hit', {
polling: 'mutation',
})
.then(() => (success = true));
await page.evaluate(async () => (window.__FOO = 'hit'));
expect(success).toBe(false);
await page.evaluate(async () =>
document.body.appendChild(document.createElement('div'))
);
await watchdog;
});
it('should poll on raf', async () => {
const { page } = getTestState();
@@ -161,6 +193,18 @@ describe('waittask specs', function () {
await page.evaluate(() => (window.__FOO = 'hit'));
await watchdog;
});
it('should poll on raf async', async () => {
const { page } = getTestState();
const watchdog = page.waitForFunction(
async () => window.__FOO === 'hit',
{
polling: 'raf',
}
);
await page.evaluate(async () => (window.__FOO = 'hit'));
await watchdog;
});
itFailsFirefox('should work with strict CSP policy', async () => {
const { page, server } = getTestState();