fix: avoid calling jsonValue from waitFor (#1746)

If the success value of `waitForFunction` was not serializable, checking whether it was truthy with `.jsonValue()` might fail. Now I check whether it was truthy inside the page.

Fixes #1737.
This commit is contained in:
JoelEinbinder 2018-01-08 14:14:41 -08:00 committed by Andrey Lushnikov
parent 8e9c54a789
commit 972f44d328
2 changed files with 4 additions and 1 deletions

View File

@ -715,7 +715,7 @@ class WaitTask {
}
// Ignore timeouts in pageScript - we track timeouts ourselves.
if (!error && !(await success.jsonValue())) {
if (!error && await this._frame.evaluate(s => !s, success)) {
await success.dispose();
return;
}

View File

@ -703,6 +703,9 @@ describe('Page', function() {
it('should return the success value as a JSHandle', async({page}) => {
expect(await (await page.waitForFunction(() => 5)).jsonValue()).toBe(5);
});
it('should return the window as a success value', async({ page }) => {
expect(await page.waitForFunction(() => window)).toBeTruthy();
});
it('should accept ElementHandle arguments', async({page}) => {
await page.setContent('<div></div>');
const div = await page.$('div');