From 8100cbb29569541541f61001983efb9a80d89890 Mon Sep 17 00:00:00 2001 From: jrandolf <101637635+jrandolf@users.noreply.github.com> Date: Fri, 24 Jun 2022 08:40:08 +0200 Subject: [PATCH] fix: infer unioned handles (#8562) --- src/api-docs-entry.ts | 40 +++++++++++++++---------------- src/common/DOMWorld.ts | 18 +++++++------- src/common/ElementHandle.ts | 14 +++++------ src/common/ExecutionContext.ts | 16 ++++++------- src/common/FrameManager.ts | 20 ++++++++-------- src/common/JSHandle.ts | 40 ++++++++++++++++++------------- src/common/Page.ts | 20 ++++++++-------- src/common/WebWorker.ts | 6 ++--- src/common/types.ts | 7 +++--- test/src/ariaqueryhandler.spec.ts | 4 ++-- test/src/evaluation.spec.ts | 4 ++-- test/src/jshandle.spec.ts | 4 ++-- test/src/queryselector.spec.ts | 9 ++++--- test/src/waittask.spec.ts | 20 ++++++++-------- 14 files changed, 116 insertions(+), 106 deletions(-) diff --git a/src/api-docs-entry.ts b/src/api-docs-entry.ts index bc53f565bd4f5..ed1a9af56dc1e 100644 --- a/src/api-docs-entry.ts +++ b/src/api-docs-entry.ts @@ -41,43 +41,43 @@ import {CustomQueryHandler} from './common/QueryHandler.js'; */ export * from './common/Accessibility.js'; export * from './common/Browser.js'; -export * from './node/BrowserFetcher.js'; -export * from './node/Puppeteer.js'; -export * from './common/Coverage.js'; +export * from './common/BrowserConnector.js'; export * from './common/Connection.js'; export * from './common/ConsoleMessage.js'; export * from './common/Coverage.js'; +export * from './common/Coverage.js'; export * from './common/DeviceDescriptors.js'; export * from './common/Dialog.js'; export * from './common/DOMWorld.js'; -export * from './common/JSHandle.js'; -export * from './common/ExecutionContext.js'; +export * from './common/Errors.js'; export * from './common/EventEmitter.js'; +export * from './common/ExecutionContext.js'; export * from './common/FileChooser.js'; export * from './common/FrameManager.js'; -export * from './common/PuppeteerViewport.js'; +export * from './common/HTTPRequest.js'; +export * from './common/HTTPResponse.js'; export * from './common/Input.js'; +export * from './common/JSHandle.js'; +export * from './common/LifecycleWatcher.js'; +export * from './common/NetworkConditions.js'; +export * from './common/NetworkManager.js'; export * from './common/Page.js'; +export * from './common/PDFOptions.js'; export * from './common/Product.js'; export * from './common/Puppeteer.js'; -export * from './common/BrowserConnector.js'; -export * from './node/ProductLauncher.js'; -export * from './node/LaunchOptions.js'; -export * from './common/HTTPRequest.js'; -export * from './common/HTTPResponse.js'; +export * from './common/PuppeteerViewport.js'; +export * from './common/QueryHandler.js'; export * from './common/SecurityDetails.js'; export * from './common/Target.js'; -export * from './common/Errors.js'; +export * from './common/TimeoutSettings.js'; export * from './common/Tracing.js'; -export * from './common/NetworkManager.js'; -export * from './common/WebWorker.js'; -export * from './common/USKeyboardLayout.js'; export * from './common/types.js'; -export * from './common/PDFOptions.js'; -export * from './common/TimeoutSettings.js'; -export * from './common/LifecycleWatcher.js'; -export * from './common/QueryHandler.js'; -export * from './common/NetworkConditions.js'; +export * from './common/USKeyboardLayout.js'; +export * from './common/WebWorker.js'; +export * from './node/BrowserFetcher.js'; +export * from './node/LaunchOptions.js'; +export * from './node/ProductLauncher.js'; +export * from './node/Puppeteer.js'; export * from 'devtools-protocol/types/protocol'; /* diff --git a/src/common/DOMWorld.ts b/src/common/DOMWorld.ts index ca8bcdf8bfcfc..713ad16f60b3d 100644 --- a/src/common/DOMWorld.ts +++ b/src/common/DOMWorld.ts @@ -26,7 +26,7 @@ import {JSHandle} from './JSHandle.js'; import {LifecycleWatcher, PuppeteerLifeCycleEvent} from './LifecycleWatcher.js'; import {_getQueryHandlerAndSelector} from './QueryHandler.js'; import {TimeoutSettings} from './TimeoutSettings.js'; -import {EvaluateFunc, EvaluateParams, HandleFor} from './types.js'; +import {EvaluateFunc, HandleFor} from './types.js'; import { debugError, isNumber, @@ -183,7 +183,7 @@ export class DOMWorld { Func extends EvaluateFunc = EvaluateFunc >( pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>>> { const context = await this.executionContext(); return context.evaluateHandle(pageFunction, ...args); @@ -194,7 +194,7 @@ export class DOMWorld { Func extends EvaluateFunc = EvaluateFunc >( pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>> { const context = await this.executionContext(); return context.evaluate(pageFunction, ...args); @@ -253,7 +253,7 @@ export class DOMWorld { >( selector: Selector, pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>>; async $eval< Params extends unknown[], @@ -263,7 +263,7 @@ export class DOMWorld { >( selector: string, pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>>; async $eval< Params extends unknown[], @@ -273,7 +273,7 @@ export class DOMWorld { >( selector: string, pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>> { const document = await this._document(); return document.$eval(selector, pageFunction, ...args); @@ -288,7 +288,7 @@ export class DOMWorld { >( selector: Selector, pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>>; async $$eval< Params extends unknown[], @@ -298,7 +298,7 @@ export class DOMWorld { >( selector: string, pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>>; async $$eval< Params extends unknown[], @@ -308,7 +308,7 @@ export class DOMWorld { >( selector: string, pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>> { const document = await this._document(); const value = await document.$$eval(selector, pageFunction, ...args); diff --git a/src/common/ElementHandle.ts b/src/common/ElementHandle.ts index aaf06c2352f3c..9429b1d6e2134 100644 --- a/src/common/ElementHandle.ts +++ b/src/common/ElementHandle.ts @@ -16,7 +16,7 @@ import { } from './JSHandle.js'; import {Page, ScreenshotOptions} from './Page.js'; import {_getQueryHandlerAndSelector} from './QueryHandler.js'; -import {EvaluateFunc, EvaluateParams} from './types.js'; +import {EvaluateFunc} from './types.js'; import {KeyInput} from './USKeyboardLayout.js'; import {debugError, isString} from './util.js'; @@ -898,7 +898,7 @@ export class ElementHandle< >( selector: Selector, pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>>; async $eval< Params extends unknown[], @@ -908,7 +908,7 @@ export class ElementHandle< >( selector: string, pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>>; async $eval< Params extends unknown[], @@ -918,7 +918,7 @@ export class ElementHandle< >( selector: string, pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>> { const elementHandle = await this.$(selector); if (!elementHandle) { @@ -963,7 +963,7 @@ export class ElementHandle< >( selector: Selector, pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>>; async $$eval< Params extends unknown[], @@ -973,7 +973,7 @@ export class ElementHandle< >( selector: string, pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>>; async $$eval< Params extends unknown[], @@ -983,7 +983,7 @@ export class ElementHandle< >( selector: string, pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>> { const {updatedSelector, queryHandler} = _getQueryHandlerAndSelector(selector); diff --git a/src/common/ExecutionContext.ts b/src/common/ExecutionContext.ts index fd02fd9d07963..3615b39c74f74 100644 --- a/src/common/ExecutionContext.ts +++ b/src/common/ExecutionContext.ts @@ -18,15 +18,15 @@ import {Protocol} from 'devtools-protocol'; import {assert} from './assert.js'; import {CDPSession} from './Connection.js'; import {DOMWorld} from './DOMWorld.js'; -import {EvaluateFunc, HandleFor, EvaluateParams} from './types.js'; +import {ElementHandle} from './ElementHandle.js'; import {Frame} from './FrameManager.js'; import {JSHandle} from './JSHandle.js'; -import {ElementHandle} from './ElementHandle.js'; +import {EvaluateFunc, HandleFor} from './types.js'; import { getExceptionMessage, - _createJSHandle, isString, valueFromRemoteObject, + _createJSHandle, } from './util.js'; /** @@ -145,7 +145,7 @@ export class ExecutionContext { Func extends EvaluateFunc = EvaluateFunc >( pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>> { return await this.#evaluate(true, pageFunction, ...args); } @@ -197,7 +197,7 @@ export class ExecutionContext { Func extends EvaluateFunc = EvaluateFunc >( pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>>> { return this.#evaluate(false, pageFunction, ...args); } @@ -208,7 +208,7 @@ export class ExecutionContext { >( returnByValue: true, pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>>; async #evaluate< Params extends unknown[], @@ -216,7 +216,7 @@ export class ExecutionContext { >( returnByValue: false, pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>>>; async #evaluate< Params extends unknown[], @@ -224,7 +224,7 @@ export class ExecutionContext { >( returnByValue: boolean, pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>> | Awaited>> { const suffix = `//# sourceURL=${EVALUATION_SCRIPT_URL}`; diff --git a/src/common/FrameManager.ts b/src/common/FrameManager.ts index b744f333938e1..658500add0b0f 100644 --- a/src/common/FrameManager.ts +++ b/src/common/FrameManager.ts @@ -27,7 +27,7 @@ import {LifecycleWatcher, PuppeteerLifeCycleEvent} from './LifecycleWatcher.js'; import {NetworkManager} from './NetworkManager.js'; import {Page} from './Page.js'; import {TimeoutSettings} from './TimeoutSettings.js'; -import {EvaluateFunc, EvaluateParams, HandleFor} from './types.js'; +import {EvaluateFunc, HandleFor} from './types.js'; import {debugError, isErrorLike} from './util.js'; const UTILITY_WORLD_NAME = '__puppeteer_utility_world__'; @@ -889,7 +889,7 @@ export class Frame { Func extends EvaluateFunc = EvaluateFunc >( pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>>> { return this._mainWorld.evaluateHandle(pageFunction, ...args); } @@ -908,7 +908,7 @@ export class Frame { Func extends EvaluateFunc = EvaluateFunc >( pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>> { return this._mainWorld.evaluate(pageFunction, ...args); } @@ -979,7 +979,7 @@ export class Frame { >( selector: Selector, pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>>; async $eval< Params extends unknown[], @@ -989,7 +989,7 @@ export class Frame { >( selector: string, pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>>; async $eval< Params extends unknown[], @@ -999,7 +999,7 @@ export class Frame { >( selector: string, pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>> { return this._mainWorld.$eval(selector, pageFunction, ...args); } @@ -1032,7 +1032,7 @@ export class Frame { >( selector: Selector, pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>>; async $$eval< Params extends unknown[], @@ -1042,7 +1042,7 @@ export class Frame { >( selector: string, pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>>; async $$eval< Params extends unknown[], @@ -1052,7 +1052,7 @@ export class Frame { >( selector: string, pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>> { return this._mainWorld.$$eval(selector, pageFunction, ...args); } @@ -1440,7 +1440,7 @@ export class Frame { >( pageFunction: Func | string, options: FrameWaitForFunctionOptions = {}, - ...args: EvaluateParams + ...args: Params ): Promise>>> { // TODO: Fix when NodeHandle has been added. return this._mainWorld.waitForFunction( diff --git a/src/common/JSHandle.ts b/src/common/JSHandle.ts index 7cd17f2bbb78f..4f540d86c20f5 100644 --- a/src/common/JSHandle.ts +++ b/src/common/JSHandle.ts @@ -17,7 +17,7 @@ import {Protocol} from 'devtools-protocol'; import {assert} from './assert.js'; import {CDPSession} from './Connection.js'; -import {EvaluateFunc, EvaluateParams, HandleFor, HandleOr} from './types.js'; +import {EvaluateFunc, HandleFor, HandleOr} from './types.js'; import {ExecutionContext} from './ExecutionContext.js'; import {MouseButton} from './Input.js'; import {releaseObject, valueFromRemoteObject, _createJSHandle} from './util.js'; @@ -121,9 +121,9 @@ export class JSHandle { } /** - * This method passes this handle as the first argument to `pageFunction`. - * If `pageFunction` returns a Promise, then `handle.evaluate` would wait - * for the promise to resolve and return its value. + * This method passes this handle as the first argument to `pageFunction`. If + * `pageFunction` returns a Promise, then `handle.evaluate` would wait for the + * promise to resolve and return its value. * * @example * ```js @@ -134,11 +134,15 @@ export class JSHandle { async evaluate< Params extends unknown[], - Func extends EvaluateFunc<[T, ...Params]> = EvaluateFunc<[T, ...Params]> + Func extends EvaluateFunc<[this, ...Params]> = EvaluateFunc< + [this, ...Params] + > >( pageFunction: Func | string, - ...args: EvaluateParams - ): Promise>> { + ...args: Params + ): // @ts-expect-error Circularity here is okay because we only need the return + // type which doesn't use `this`. + Promise>> { return await this.executionContext().evaluate(pageFunction, this, ...args); } @@ -148,22 +152,26 @@ export class JSHandle { * @remarks * * The only difference between `jsHandle.evaluate` and - * `jsHandle.evaluateHandle` is that `jsHandle.evaluateHandle` - * returns an in-page object (JSHandle). + * `jsHandle.evaluateHandle` is that `jsHandle.evaluateHandle` returns an + * in-page object (JSHandle). * - * If the function passed to `jsHandle.evaluateHandle` returns a Promise, - * then `evaluateHandle.evaluateHandle` waits for the promise to resolve and + * If the function passed to `jsHandle.evaluateHandle` returns a Promise, then + * `evaluateHandle.evaluateHandle` waits for the promise to resolve and * returns its value. * * See {@link Page.evaluateHandle} for more details. */ async evaluateHandle< Params extends unknown[], - Func extends EvaluateFunc<[T, ...Params]> = EvaluateFunc<[T, ...Params]> + Func extends EvaluateFunc<[this, ...Params]> = EvaluateFunc< + [this, ...Params] + > >( pageFunction: Func, - ...args: EvaluateParams - ): Promise>>> { + ...args: Params + ): // @ts-expect-error Circularity here is okay because we only need the return + // type which doesn't use `this`. + Promise>>> { return await this.executionContext().evaluateHandle( pageFunction, this, @@ -187,8 +195,8 @@ export class JSHandle { } /** - * The method returns a map with property names as keys and JSHandle - * instances for the property values. + * The method returns a map with property names as keys and JSHandle instances + * for the property values. * * @example * ```js diff --git a/src/common/Page.ts b/src/common/Page.ts index a58a9bed1582d..4a3e471f04ccb 100644 --- a/src/common/Page.ts +++ b/src/common/Page.ts @@ -49,7 +49,7 @@ import {Target} from './Target.js'; import {TaskQueue} from './TaskQueue.js'; import {TimeoutSettings} from './TimeoutSettings.js'; import {Tracing} from './Tracing.js'; -import {EvaluateFunc, EvaluateParams, HandleFor} from './types.js'; +import {EvaluateFunc, HandleFor} from './types.js'; import { debugError, evaluationString, @@ -1083,7 +1083,7 @@ export class Page extends EventEmitter { Func extends EvaluateFunc = EvaluateFunc >( pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>>> { const context = await this.mainFrame().executionContext(); return context.evaluateHandle(pageFunction, ...args); @@ -1190,7 +1190,7 @@ export class Page extends EventEmitter { >( selector: Selector, pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>>; async $eval< Params extends unknown[], @@ -1200,7 +1200,7 @@ export class Page extends EventEmitter { >( selector: string, pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>>; async $eval< Params extends unknown[], @@ -1210,7 +1210,7 @@ export class Page extends EventEmitter { >( selector: string, pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>> { return this.mainFrame().$eval(selector, pageFunction, ...args); } @@ -1286,7 +1286,7 @@ export class Page extends EventEmitter { >( selector: Selector, pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>>; async $$eval< Params extends unknown[], @@ -1296,7 +1296,7 @@ export class Page extends EventEmitter { >( selector: string, pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>>; async $$eval< Params extends unknown[], @@ -1306,7 +1306,7 @@ export class Page extends EventEmitter { >( selector: string, pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>> { return this.mainFrame().$$eval(selector, pageFunction, ...args); } @@ -2683,7 +2683,7 @@ export class Page extends EventEmitter { Func extends EvaluateFunc = EvaluateFunc >( pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>> { return this.#frameManager.mainFrame().evaluate(pageFunction, ...args); } @@ -3464,7 +3464,7 @@ export class Page extends EventEmitter { timeout?: number; polling?: string | number; } = {}, - ...args: EvaluateParams + ...args: Params ): Promise>>> { return this.mainFrame().waitForFunction(pageFunction, options, ...args); } diff --git a/src/common/WebWorker.ts b/src/common/WebWorker.ts index d7811aa8c6b93..c8ab27a9b230c 100644 --- a/src/common/WebWorker.ts +++ b/src/common/WebWorker.ts @@ -16,7 +16,7 @@ import {Protocol} from 'devtools-protocol'; import {CDPSession} from './Connection.js'; import {ConsoleMessageType} from './ConsoleMessage.js'; -import {EvaluateFunc, EvaluateParams, HandleFor} from './types.js'; +import {EvaluateFunc, HandleFor} from './types.js'; import {EventEmitter} from './EventEmitter.js'; import {ExecutionContext} from './ExecutionContext.js'; import {JSHandle} from './JSHandle.js'; @@ -141,7 +141,7 @@ export class WebWorker extends EventEmitter { Func extends EvaluateFunc = EvaluateFunc >( pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>> { return (await this.#executionContextPromise).evaluate( pageFunction, @@ -166,7 +166,7 @@ export class WebWorker extends EventEmitter { Func extends EvaluateFunc = EvaluateFunc >( pageFunction: Func | string, - ...args: EvaluateParams + ...args: Params ): Promise>>> { return (await this.#executionContextPromise).evaluateHandle( pageFunction, diff --git a/src/common/types.ts b/src/common/types.ts index 01c31d7f822d6..4bbe8ab2f38a2 100644 --- a/src/common/types.ts +++ b/src/common/types.ts @@ -22,12 +22,11 @@ export type Awaitable = T | PromiseLike; export type HandleFor = T extends Element ? ElementHandle : JSHandle; export type HandleOr = HandleFor | JSHandle | T; -export type EvaluateParams = { - [K in keyof T]: T[K] extends HandleOr ? T[K] : HandleOr; -}; +type FlattenHandle = T extends HandleOr ? U : never; export type InnerParams = { - [K in keyof T]: T[K] extends HandleOr ? U : never; + [K in keyof T]: FlattenHandle; }; + export type EvaluateFunc = ( ...params: InnerParams ) => Awaitable; diff --git a/test/src/ariaqueryhandler.spec.ts b/test/src/ariaqueryhandler.spec.ts index f5ecfdd666c4a..d709c14aa46d8 100644 --- a/test/src/ariaqueryhandler.spec.ts +++ b/test/src/ariaqueryhandler.spec.ts @@ -557,8 +557,8 @@ describeChromeOnly('AriaQueryHandler', () => { const waitForSelector = page.waitForSelector('aria/zombo'); await page.setContent(`
anything
`); expect( - await page.evaluate((x: HTMLElement) => { - return x.textContent; + await page.evaluate(x => { + return x?.textContent; }, await waitForSelector) ).toBe('anything'); }); diff --git a/test/src/evaluation.spec.ts b/test/src/evaluation.spec.ts index 6cd9cc251d0b2..a4a39f5739422 100644 --- a/test/src/evaluation.spec.ts +++ b/test/src/evaluation.spec.ts @@ -419,8 +419,8 @@ describe('Evaluation specs', function () { const bodyHandle = await page.frames()[1]!.$('body'); let error!: Error; await page - .evaluate((body: HTMLElement) => { - return body.innerHTML; + .evaluate(body => { + return body?.innerHTML; }, bodyHandle) .catch(error_ => { return (error = error_); diff --git a/test/src/jshandle.spec.ts b/test/src/jshandle.spec.ts index 2651bf3330595..6d38f724bf631 100644 --- a/test/src/jshandle.spec.ts +++ b/test/src/jshandle.spec.ts @@ -245,8 +245,8 @@ describe('JSHandle', function () { const element = aHandle.asElement(); expect(element).toBeTruthy(); expect( - await page.evaluate((e: HTMLElement) => { - return e.nodeType === Node.TEXT_NODE; + await page.evaluate(e => { + return e?.nodeType === Node.TEXT_NODE; }, element) ); }); diff --git a/test/src/queryselector.spec.ts b/test/src/queryselector.spec.ts index 9881d5e4f965c..2f0ad2a1bd777 100644 --- a/test/src/queryselector.spec.ts +++ b/test/src/queryselector.spec.ts @@ -284,8 +284,8 @@ describe('querySelector', function () { const html = (await page.$('html'))!; const second = (await html.$('.second'))!; const inner = await second.$('.inner'); - const content = await page.evaluate((e: HTMLElement) => { - return e.textContent; + const content = await page.evaluate(e => { + return e?.textContent; }, inner); expect(content).toBe('A'); }); @@ -456,7 +456,10 @@ describe('querySelector', function () { describe('QueryAll', function () { const handler: CustomQueryHandler = { queryAll: (element, selector) => { - return Array.from(element.querySelectorAll(selector)); + if (element instanceof Document || element instanceof Element) { + return element.querySelectorAll(selector); + } + return []; }, }; before(() => { diff --git a/test/src/waittask.spec.ts b/test/src/waittask.spec.ts index b75d19f744931..81b8809741c96 100644 --- a/test/src/waittask.spec.ts +++ b/test/src/waittask.spec.ts @@ -433,8 +433,8 @@ describe('waittask specs', function () { page.setContent(`
anything
`), ]); expect( - await page.evaluate((x: HTMLElement) => { - return x.textContent; + await page.evaluate(x => { + return x?.textContent; }, handle) ).toBe('anything'); }); @@ -690,8 +690,8 @@ describe('waittask specs', function () { const waitForSelector = page.waitForSelector('.zombo'); await page.setContent(`
anything
`); expect( - await page.evaluate((x: HTMLElement) => { - return x.textContent; + await page.evaluate(x => { + return x?.textContent; }, await waitForSelector) ).toBe('anything'); }); @@ -721,8 +721,8 @@ describe('waittask specs', function () { '//p[normalize-space(.)="hello world"]' ); expect( - await page.evaluate((x: HTMLElement) => { - return x.textContent; + await page.evaluate(x => { + return x?.textContent; }, await waitForXPath) ).toBe('hello world '); }); @@ -795,8 +795,8 @@ describe('waittask specs', function () { const waitForXPath = page.waitForXPath('//*[@class="zombo"]'); await page.setContent(`
anything
`); expect( - await page.evaluate((x: HTMLElement) => { - return x.textContent; + await page.evaluate(x => { + return x?.textContent; }, await waitForXPath) ).toBe('anything'); }); @@ -815,8 +815,8 @@ describe('waittask specs', function () { await page.setContent(`
some text
`); const waitForXPath = page.waitForXPath('/html/body/div'); expect( - await page.evaluate((x: HTMLElement) => { - return x.textContent; + await page.evaluate(x => { + return x?.textContent; }, await waitForXPath) ).toBe('some text'); });