Events created using the Event constructor with { bubbles: true } do not bubble to parent elements, even though event.bubbles is correctly set to true.
Reproduction
const { Window } = require('happy-dom');
const window = new Window();
const document = window.document;
const parent = document.createElement('div');
const child = document.createElement('span');
parent.appendChild(child);
document.body.appendChild(parent);
let bubbled = false;
parent.addEventListener('click', () => {
bubbled = true;
});
const event = new Event('click', { bubbles: true });
console.log('event.bubbles:', event.bubbles); // true ✓
child.dispatchEvent(event);
console.log('bubbled to parent:', bubbled); // false ✗ (should be true)
Expected behavior
The event should bubble from child to parent, triggering the parent's event listener.
Actual behavior
event.bubbles is correctly true
- Event fires on
child
- Event does NOT bubble to
parent
- Parent's listener is never called
Workaround
Using the legacy createEvent/initEvent API works correctly:
const event = document.createEvent('Event');
event.initEvent('click', true, true); // (type, bubbles, cancelable)
child.dispatchEvent(event);
console.log('bubbled to parent:', bubbled); // true ✓
Impact
This breaks any code using the modern Event constructor API for custom events or synthetic event dispatching. Many testing libraries and frameworks rely on this for simulating user interactions.
Environment
- happy-dom version: 16.7.2
- Node.js version: v22.x
Events created using the
Eventconstructor with{ bubbles: true }do not bubble to parent elements, even thoughevent.bubblesis correctly set totrue.Reproduction
Expected behavior
The event should bubble from
childtoparent, triggering the parent's event listener.Actual behavior
event.bubblesis correctlytruechildparentWorkaround
Using the legacy
createEvent/initEventAPI works correctly:Impact
This breaks any code using the modern Event constructor API for custom events or synthetic event dispatching. Many testing libraries and frameworks rely on this for simulating user interactions.
Environment