fix(fill): allow to clear number input (#2376)
This commit is contained in:
parent
11d53ad529
commit
4413138cc6
|
|
@ -211,7 +211,7 @@ export default class InjectedScript {
|
||||||
return { status: 'error', error: 'Cannot fill input of type "' + type + '".' };
|
return { status: 'error', error: 'Cannot fill input of type "' + type + '".' };
|
||||||
if (type === 'number') {
|
if (type === 'number') {
|
||||||
value = value.trim();
|
value = value.trim();
|
||||||
if (!value || isNaN(Number(value)))
|
if (isNaN(Number(value)))
|
||||||
return { status: 'error', error: 'Cannot type text into input[type=number].' };
|
return { status: 'error', error: 'Cannot type text into input[type=number].' };
|
||||||
}
|
}
|
||||||
if (input.disabled)
|
if (input.disabled)
|
||||||
|
|
|
||||||
|
|
@ -1164,16 +1164,15 @@ describe('Page.fill', function() {
|
||||||
await page.fill('input', '-10e5');
|
await page.fill('input', '-10e5');
|
||||||
expect(await page.evaluate(() => input.value)).toBe('-10e5');
|
expect(await page.evaluate(() => input.value)).toBe('-10e5');
|
||||||
});
|
});
|
||||||
it('should not be able to fill input[type=number] with empty string', async({page}) => {
|
it('should be able to fill input[type=number] with empty string', async({page}) => {
|
||||||
await page.setContent(`<input id="input" type="number"></input>`);
|
await page.setContent(`<input id="input" type="number" value="123"></input>`);
|
||||||
let error = null;
|
await page.fill('input', '');
|
||||||
await page.fill('input', '').catch(e => error = e);
|
expect(await page.evaluate(() => input.value)).toBe('');
|
||||||
expect(error.message).toContain('Cannot type text into input[type=number].');
|
|
||||||
});
|
});
|
||||||
it('should not be able to fill text into the input[type=number]', async({page}) => {
|
it('should not be able to fill text into the input[type=number]', async({page}) => {
|
||||||
await page.setContent(`<input id="input" type="number"></input>`);
|
await page.setContent(`<input id="input" type="number"></input>`);
|
||||||
let error = null;
|
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].');
|
expect(error.message).toContain('Cannot type text into input[type=number].');
|
||||||
});
|
});
|
||||||
it('should be able to clear', async({page, server}) => {
|
it('should be able to clear', async({page, server}) => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue