chore: locator code style nits (#7972)

This commit is contained in:
Max Schmitt 2021-08-03 22:32:39 +02:00 committed by GitHub
parent c406b23387
commit 2236d74f3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 11 deletions

View File

@ -34,10 +34,10 @@ export class Locator implements api.Locator {
private async _withElement<R, O extends TimeoutOptions>(task: (handle: ElementHandle<SVGElement | HTMLElement>, options?: O) => Promise<R>, options?: O): Promise<R> { private async _withElement<R, O extends TimeoutOptions>(task: (handle: ElementHandle<SVGElement | HTMLElement>, options?: O) => Promise<R>, options?: O): Promise<R> {
if (!options) if (!options)
options = {} as any; options = {} as O;
const timeout = this._frame.page()._timeoutSettings.timeout(options!); const timeout = this._frame.page()._timeoutSettings.timeout(options!);
const deadline = timeout ? monotonicTime() + timeout : 0; const deadline = timeout ? monotonicTime() + timeout : 0;
const handle = await this.elementHandle(options); const handle = await this.elementHandle({ timeout });
if (!handle) if (!handle)
throw new Error(`Could not resolve ${this._selector} to DOM Element`); throw new Error(`Could not resolve ${this._selector} to DOM Element`);
try { try {
@ -68,15 +68,15 @@ export class Locator implements api.Locator {
} }
async evaluate<R, Arg>(pageFunction: structs.PageFunctionOn<SVGElement | HTMLElement, Arg, R>, arg?: Arg, options?: TimeoutOptions): Promise<R> { async evaluate<R, Arg>(pageFunction: structs.PageFunctionOn<SVGElement | HTMLElement, Arg, R>, arg?: Arg, options?: TimeoutOptions): Promise<R> {
return this._withElement(h => h.evaluate(pageFunction as any, arg), { strict: true, ...options }); return this._withElement(h => h.evaluate(pageFunction, arg), { strict: true, ...options });
} }
async evaluateAll<R, Arg>(pageFunction: structs.PageFunctionOn<(SVGElement | HTMLElement)[], Arg, R>, arg?: Arg): Promise<R> { async evaluateAll<R, Arg>(pageFunction: structs.PageFunctionOn<Element[], Arg, R>, arg?: Arg): Promise<R> {
return this._frame.$$eval(this._selector, pageFunction as any, arg); return this._frame.$$eval(this._selector, pageFunction, arg);
} }
async evaluateHandle<R, Arg>(pageFunction: structs.PageFunction<Arg, R>, arg?: Arg, options?: TimeoutOptions): Promise<structs.SmartHandle<R>> { async evaluateHandle<R, Arg>(pageFunction: structs.PageFunctionOn<any, Arg, R>, arg?: Arg, options?: TimeoutOptions): Promise<structs.SmartHandle<R>> {
return this._withElement(h => h.evaluateHandle(pageFunction as any, arg), { strict: true, ...options }); return this._withElement(h => h.evaluateHandle(pageFunction, arg), { strict: true, ...options });
} }
async fill(value: string, options: channels.ElementHandleFillOptions = {}): Promise<void> { async fill(value: string, options: channels.ElementHandleFillOptions = {}): Promise<void> {
@ -88,8 +88,7 @@ export class Locator implements api.Locator {
} }
async elementHandle(options?: TimeoutOptions): Promise<ElementHandle<SVGElement | HTMLElement>> { async elementHandle(options?: TimeoutOptions): Promise<ElementHandle<SVGElement | HTMLElement>> {
const result = await this._frame.waitForSelector(this._selector, { strict: true, state: 'attached', ...options }); return await this._frame.waitForSelector(this._selector, { strict: true, state: 'attached', ...options })!;
return result!;
} }
async elementHandles(): Promise<api.ElementHandle<SVGElement | HTMLElement>[]> { async elementHandles(): Promise<api.ElementHandle<SVGElement | HTMLElement>[]> {

View File

@ -200,12 +200,12 @@ it('isChecked should work', async ({page}) => {
expect(error.message).toContain('Not a checkbox or radio button'); expect(error.message).toContain('Not a checkbox or radio button');
}); });
it('addTextContents should work', async ({page}) => { it('allTextContents should work', async ({page}) => {
await page.setContent(`<div>A</div><div>B</div><div>C</div>`); await page.setContent(`<div>A</div><div>B</div><div>C</div>`);
expect(await page.locator('div').allTextContents()).toEqual(['A', 'B', 'C']); expect(await page.locator('div').allTextContents()).toEqual(['A', 'B', 'C']);
}); });
it('addInnerTexts should work', async ({page}) => { it('allInnerTexts should work', async ({page}) => {
await page.setContent(`<div>A</div><div>B</div><div>C</div>`); await page.setContent(`<div>A</div><div>B</div><div>C</div>`);
expect(await page.locator('div').allInnerTexts()).toEqual(['A', 'B', 'C']); expect(await page.locator('div').allInnerTexts()).toEqual(['A', 'B', 'C']);
}); });