fix(page): respect timeout 0 in page.waitForFunction (#2563)
The in-page task should not set timeout when timeout is 0. Fixes #2540.
This commit is contained in:
parent
6a0627a411
commit
debfe7e0b1
@ -911,7 +911,8 @@ class WaitTask {
|
|||||||
async function waitForPredicatePageFunction(predicateBody, polling, timeout, ...args) {
|
async function waitForPredicatePageFunction(predicateBody, polling, timeout, ...args) {
|
||||||
const predicate = new Function('...args', predicateBody);
|
const predicate = new Function('...args', predicateBody);
|
||||||
let timedOut = false;
|
let timedOut = false;
|
||||||
setTimeout(() => timedOut = true, timeout);
|
if (timeout)
|
||||||
|
setTimeout(() => timedOut = true, timeout);
|
||||||
if (polling === 'raf')
|
if (polling === 'raf')
|
||||||
return await pollRaf();
|
return await pollRaf();
|
||||||
if (polling === 'mutation')
|
if (polling === 'mutation')
|
||||||
|
@ -159,10 +159,13 @@ module.exports.addTests = function({testRunner, expect}) {
|
|||||||
expect(error.message).toContain('waiting for function failed: timeout');
|
expect(error.message).toContain('waiting for function failed: timeout');
|
||||||
});
|
});
|
||||||
it('should disable timeout when its set to 0', async({page}) => {
|
it('should disable timeout when its set to 0', async({page}) => {
|
||||||
let error = null;
|
const watchdog = page.waitForFunction(() => {
|
||||||
const res = await page.waitForFunction(() => new Promise(res => setTimeout(() => res(42), 100)), {timeout: 0}).catch(e => error = e);
|
window.__counter = (window.__counter || 0) + 1;
|
||||||
expect(error).toBe(null);
|
return window.__injected;
|
||||||
expect(await res.jsonValue()).toBe(42);
|
}, {timeout: 0, polling: 10});
|
||||||
|
await page.waitForFunction(() => window.__counter > 10);
|
||||||
|
await page.evaluate(() => window.__injected = true);
|
||||||
|
await watchdog;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user