Skip to content

Commit

Permalink
fix(Page.select): synthesized events should bubble
Browse files Browse the repository at this point in the history
This patch fixes `Page.select` to synthesize bubbling events.
  • Loading branch information
ChristianDavis authored and aslushnikov committed Oct 7, 2017
1 parent 44cdf85 commit 3ecd98d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/Page.js
Expand Up @@ -732,9 +732,8 @@ class Page extends EventEmitter {
} else {
element.value = values.shift();
}

element.dispatchEvent(new Event('change'));
element.dispatchEvent(new Event('input'));
element.dispatchEvent(new Event('input', { 'bubbles': true }));
element.dispatchEvent(new Event('change', { 'bubbles': true }));
}, values);
}

Expand Down
14 changes: 14 additions & 0 deletions test/assets/input/select.html
Expand Up @@ -25,6 +25,8 @@
window.result = {
onInput: null,
onChange: null,
onBubblingChange: null,
onBubblingInput: null,
};

let select = document.querySelector('select');
Expand All @@ -50,6 +52,18 @@
return option.value;
});
}, false);

document.body.addEventListener('input', () => {
result.onBubblingInput = Array.from(select.querySelectorAll('option:checked')).map((option) => {
return option.value;
});
}, false);

document.body.addEventListener('change', () => {
result.onBubblingChange = Array.from(select.querySelectorAll('option:checked')).map((option) => {
return option.value;
});
}, false);
</script>
</body>
</html>
7 changes: 7 additions & 0 deletions test/test.js
Expand Up @@ -2244,6 +2244,13 @@ describe('Page', function() {
expect(await page.evaluate(() => result.onChange)).toEqual(['blue', 'green', 'red']);
}));

it('should respect event bubbling', SX(async function() {
await page.goto(PREFIX + '/input/select.html');
await page.select('select', 'blue');
expect(await page.evaluate(() => result.onBubblingInput)).toEqual(['blue']);
expect(await page.evaluate(() => result.onBubblingChange)).toEqual(['blue']);
}));

it('should work with no options', SX(async function() {
await page.goto(PREFIX + '/input/select.html');
await page.evaluate(() => makeEmpty());
Expand Down

0 comments on commit 3ecd98d

Please sign in to comment.