diff --git a/lib/JSHandle.js b/lib/JSHandle.js index e5ff00416f4ca..fc88ff7741c8d 100644 --- a/lib/JSHandle.js +++ b/lib/JSHandle.js @@ -341,6 +341,7 @@ class ElementHandle extends JSHandle { } element.files = dt.files; element.dispatchEvent(new Event('input', { bubbles: true })); + element.dispatchEvent(new Event('change', { bubbles: true })); }, files); } diff --git a/test/input.spec.js b/test/input.spec.js index 6b768983555cb..39ef35ab1fa16 100644 --- a/test/input.spec.js +++ b/test/input.spec.js @@ -27,8 +27,14 @@ module.exports.addTests = function({testRunner, expect, puppeteer}) { await page.goto(server.PREFIX + '/input/fileupload.html'); const filePath = path.relative(process.cwd(), FILE_TO_UPLOAD); const input = await page.$('input'); + await page.evaluate(e => { + window._inputEvents = []; + e.addEventListener('change', ev => window._inputEvents.push(ev.type)); + e.addEventListener('input', ev => window._inputEvents.push(ev.type)); + }, input); await input.uploadFile(filePath); expect(await page.evaluate(e => e.files[0].name, input)).toBe('file-to-upload.txt'); + expect(await page.evaluate(() => window._inputEvents)).toEqual(['input', 'change']); expect(await page.evaluate(e => { const reader = new FileReader(); const promise = new Promise(fulfill => reader.onload = fulfill);