fix(fill): allow to clear number input (#2376)

This commit is contained in:
Dmitry Gozman 2020-05-27 20:01:08 -07:00 committed by GitHub
parent 11d53ad529
commit 4413138cc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 7 deletions

View File

@ -211,7 +211,7 @@ export default class InjectedScript {
return { status: 'error', error: 'Cannot fill input of type "' + type + '".' };
if (type === 'number') {
value = value.trim();
if (!value || isNaN(Number(value)))
if (isNaN(Number(value)))
return { status: 'error', error: 'Cannot type text into input[type=number].' };
}
if (input.disabled)

View File

@ -1164,16 +1164,15 @@ describe('Page.fill', function() {
await page.fill('input', '-10e5');
expect(await page.evaluate(() => input.value)).toBe('-10e5');
});
it('should not be able to fill input[type=number] with empty string', async({page}) => {
await page.setContent(`<input id="input" type="number"></input>`);
let error = null;
await page.fill('input', '').catch(e => error = e);
expect(error.message).toContain('Cannot type text into input[type=number].');
it('should be able to fill input[type=number] with empty string', async({page}) => {
await page.setContent(`<input id="input" type="number" value="123"></input>`);
await page.fill('input', '');
expect(await page.evaluate(() => input.value)).toBe('');
});
it('should not be able to fill text into the input[type=number]', async({page}) => {
await page.setContent(`<input id="input" type="number"></input>`);
let error = null;
await page.fill('input', '').catch(e => error = e);
await page.fill('input', 'abc').catch(e => error = e);
expect(error.message).toContain('Cannot type text into input[type=number].');
});
it('should be able to clear', async({page, server}) => {