Skip to content

Commit 978dbfa

Browse files
authored
chore: [#1661] Adds unit test for testing bubbling of events (#1679)
1 parent 3218bf9 commit 978dbfa

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

packages/happy-dom/test/nodes/node/Node.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,48 @@ describe('Node', () => {
11351135
true
11361136
);
11371137
});
1138+
1139+
it('Handles bubbling events correctly for issue #1661', () => {
1140+
window.document.body.innerHTML = '<div><button>Click Me!</button></div>';
1141+
1142+
const div = <HTMLElement>window.document.querySelector('div');
1143+
const button = <HTMLElement>window.document.querySelector('button');
1144+
const outputs: string[] = [];
1145+
1146+
for (const node of [div, button]) {
1147+
node.addEventListener('click', () => {
1148+
outputs.push('click:' + node.nodeName);
1149+
});
1150+
1151+
node.addEventListener('a', () => {
1152+
outputs.push('a:' + node.nodeName);
1153+
});
1154+
1155+
node.addEventListener('b', () => {
1156+
outputs.push('b:' + node.nodeName);
1157+
});
1158+
1159+
node.addEventListener('c', () => {
1160+
outputs.push('c:' + node.nodeName);
1161+
});
1162+
}
1163+
1164+
button.click();
1165+
button.dispatchEvent(new Event('a', { bubbles: true }));
1166+
button.dispatchEvent(new Event('b', { bubbles: true }));
1167+
button.dispatchEvent(new Event('c', { bubbles: true }));
1168+
1169+
expect(outputs).toEqual([
1170+
'click:BUTTON',
1171+
'click:DIV',
1172+
'a:BUTTON',
1173+
'a:DIV',
1174+
'b:BUTTON',
1175+
'b:DIV',
1176+
'c:BUTTON',
1177+
'c:DIV'
1178+
]);
1179+
});
11381180
});
11391181

11401182
describe('compareDocumentPosition()', () => {

0 commit comments

Comments
 (0)