fix(page): teach waitForSelector to return null (#3846)

`page.waitForSelector` should return `null` if waiting for `hidden:
true` and there's no matching node in DOM.

Before this patch, `page.waitForSelector` would return some JSHandle
pointing to boolean value.
This commit is contained in:
Andrey Lushnikov
2019-01-28 14:24:53 -05:00
committed by GitHub
parent 7446550fdb
commit 2061dd4718
5 changed files with 32 additions and 15 deletions

View File

@@ -17,6 +17,13 @@
const utils = require('./utils');
const {TimeoutError} = utils.requireRoot('Errors');
let asyncawait = true;
try {
new Function('async function foo() {await 1}');
} catch (e) {
asyncawait = false;
}
module.exports.addTests = function({testRunner, expect, product}) {
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit} = testRunner;
@@ -322,6 +329,10 @@ module.exports.addTests = function({testRunner, expect, product}) {
expect(await waitForSelector).toBe(true);
expect(divRemoved).toBe(true);
});
it('should return null if waiting to hide non-existing element', async({page, server}) => {
const handle = await page.waitForSelector('non-existing', { hidden: true });
expect(handle).toBe(null);
});
it('should respect timeout', async({page, server}) => {
let error = null;
await page.waitForSelector('div', {timeout: 10}).catch(e => error = e);
@@ -350,7 +361,7 @@ module.exports.addTests = function({testRunner, expect, product}) {
await page.setContent(`<div class='zombo'>anything</div>`);
expect(await page.evaluate(x => x.textContent, await waitForSelector)).toBe('anything');
});
it('should have correct stack trace for timeout', async({page, server}) => {
(asyncawait ? it : xit)('should have correct stack trace for timeout', async({page, server}) => {
let error;
await page.waitForSelector('.zombo', {timeout: 10}).catch(e => error = e);
expect(error.stack).toContain('waittask.spec.js');