feat(select): don't accept undefined as a value (#1202)

`page.select` accepting an `undefined` value is a legacy of when `page.select` took `...values`. This matches the way the method is documented in the API.
This commit is contained in:
Joel Einbinder 2020-03-03 16:59:41 -08:00 коммит произвёл GitHub
Родитель 4556513c2a
Коммит fcfe887c57
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 6 добавлений и 6 удалений

Просмотреть файл

@ -815,9 +815,9 @@ export class Frame {
await handle.dispose();
}
async select(selector: string, value: string | dom.ElementHandle | types.SelectOption | string[] | dom.ElementHandle[] | types.SelectOption[] | undefined, options?: types.WaitForOptions): Promise<string[]> {
async select(selector: string, value: string | dom.ElementHandle | types.SelectOption | string[] | dom.ElementHandle[] | types.SelectOption[], options?: types.WaitForOptions): Promise<string[]> {
const handle = await this._optionallyWaitForSelectorInUtilityContext(selector, options);
const values = value === undefined ? [] : Array.isArray(value) ? value : [value];
const values = Array.isArray(value) ? value : [value];
const result = await handle.select(...values);
await handle.dispose();
return result;

Просмотреть файл

@ -472,7 +472,7 @@ export class Page extends platform.EventEmitter {
return this.mainFrame().hover(selector, options);
}
async select(selector: string, value: string | dom.ElementHandle | types.SelectOption | string[] | dom.ElementHandle[] | types.SelectOption[] | undefined, options?: types.WaitForOptions): Promise<string[]> {
async select(selector: string, value: string | dom.ElementHandle | types.SelectOption | string[] | dom.ElementHandle[] | types.SelectOption[], options?: types.WaitForOptions): Promise<string[]> {
return this.mainFrame().select(selector, value, options);
}

Просмотреть файл

@ -886,20 +886,20 @@ module.exports.describe = function({testRunner, expect, headless, playwright, FF
});
it('should return [] on no values',async({page, server}) => {
await page.goto(server.PREFIX + '/input/select.html');
const result = await page.select('select');
const result = await page.select('select', []);
expect(result).toEqual([]);
});
it('should deselect all options when passed no values for a multiple select',async({page, server}) => {
await page.goto(server.PREFIX + '/input/select.html');
await page.evaluate(() => makeMultiple());
await page.select('select', ['blue','black','magenta']);
await page.select('select');
await page.select('select', []);
expect(await page.$eval('select', select => Array.from(select.options).every(option => !option.selected))).toEqual(true);
});
it('should deselect all options when passed no values for a select without multiple',async({page, server}) => {
await page.goto(server.PREFIX + '/input/select.html');
await page.select('select', ['blue','black','magenta']);
await page.select('select');
await page.select('select', []);
expect(await page.$eval('select', select => Array.from(select.options).every(option => !option.selected))).toEqual(true);
});
it('should throw if passed wrong types', async({page, server}) => {