Skip to content

Commit

Permalink
chore: [#1661] Adds unit test for testing bubbling of events (#1679)
Browse files Browse the repository at this point in the history
  • Loading branch information
capricorn86 authored Jan 8, 2025
1 parent 3218bf9 commit 978dbfa
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions packages/happy-dom/test/nodes/node/Node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,48 @@ describe('Node', () => {
true
);
});

it('Handles bubbling events correctly for issue #1661', () => {
window.document.body.innerHTML = '<div><button>Click Me!</button></div>';

const div = <HTMLElement>window.document.querySelector('div');
const button = <HTMLElement>window.document.querySelector('button');
const outputs: string[] = [];

for (const node of [div, button]) {
node.addEventListener('click', () => {
outputs.push('click:' + node.nodeName);
});

node.addEventListener('a', () => {
outputs.push('a:' + node.nodeName);
});

node.addEventListener('b', () => {
outputs.push('b:' + node.nodeName);
});

node.addEventListener('c', () => {
outputs.push('c:' + node.nodeName);
});
}

button.click();
button.dispatchEvent(new Event('a', { bubbles: true }));
button.dispatchEvent(new Event('b', { bubbles: true }));
button.dispatchEvent(new Event('c', { bubbles: true }));

expect(outputs).toEqual([
'click:BUTTON',
'click:DIV',
'a:BUTTON',
'a:DIV',
'b:BUTTON',
'b:DIV',
'c:BUTTON',
'c:DIV'
]);
});
});

describe('compareDocumentPosition()', () => {
Expand Down

0 comments on commit 978dbfa

Please sign in to comment.