diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index 34049b3580f9..0c75665c67e1 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -742,9 +742,7 @@ export function toggle_class(element, name, toggle) { } export function custom_event(type: string, detail?: T, { bubbles = false, cancelable = false } = {}): CustomEvent { - const e: CustomEvent = document.createEvent('CustomEvent'); - e.initCustomEvent(type, bubbles, cancelable, detail); - return e; + return new CustomEvent(type, { detail, bubbles, cancelable }); } export function query_selector_all(selector: string, parent: HTMLElement = document.body) { diff --git a/test/helpers.ts b/test/helpers.ts index 1ea0b198807c..dc0cdc693a35 100644 --- a/test/helpers.ts +++ b/test/helpers.ts @@ -61,6 +61,7 @@ global.navigator = window.navigator; global.getComputedStyle = window.getComputedStyle; global.requestAnimationFrame = null; // placeholder, filled in using set_raf global.window = window; +global.CustomEvent = window.CustomEvent; // add missing ecmascript globals to window for (const key of Object.getOwnPropertyNames(global)) {