fix: allow setting input files for detached <input> elements (#5467)
Fixes #5403
This commit is contained in:
parent
4f1d84d6b9
commit
6b40d75d03
|
|
@ -529,8 +529,6 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
|
|||
const multiple = throwFatalDOMError(await this._evaluateInUtility(([injected, node]): 'error:notinput' | 'error:notconnected' | boolean => {
|
||||
if (node.nodeType !== Node.ELEMENT_NODE || (node as Node as Element).tagName !== 'INPUT')
|
||||
return 'error:notinput';
|
||||
if (!node.isConnected)
|
||||
return 'error:notconnected';
|
||||
const input = node as Node as HTMLInputElement;
|
||||
return input.multiple;
|
||||
}, {}));
|
||||
|
|
|
|||
|
|
@ -104,15 +104,20 @@ it('should work when file input is attached to DOM', async ({page, server}) => {
|
|||
});
|
||||
|
||||
it('should work when file input is not attached to DOM', async ({page, server}) => {
|
||||
const [chooser] = await Promise.all([
|
||||
page.waitForEvent('filechooser'),
|
||||
page.evaluate(() => {
|
||||
const [,content] = await Promise.all([
|
||||
page.waitForEvent('filechooser').then(chooser => chooser.setFiles(FILE_TO_UPLOAD)),
|
||||
page.evaluate(async () => {
|
||||
const el = document.createElement('input');
|
||||
el.type = 'file';
|
||||
el.click();
|
||||
await new Promise(x => el.oninput = x);
|
||||
const reader = new FileReader();
|
||||
const promise = new Promise(fulfill => reader.onload = fulfill);
|
||||
reader.readAsText(el.files[0]);
|
||||
return promise.then(() => reader.result);
|
||||
}),
|
||||
]);
|
||||
expect(chooser).toBeTruthy();
|
||||
expect(content).toBe('contents of the file');
|
||||
});
|
||||
|
||||
it('should not throw when filechooser belongs to iframe', (test, { browserName }) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue