|
1 | 1 | import {debounce} from 'throttle-debounce'; |
2 | 2 | import type {Promisable} from 'type-fest'; |
3 | 3 | import type $ from 'jquery'; |
| 4 | +import {isInFrontendUnitTest} from './testhelper.ts'; |
4 | 5 |
|
5 | 6 | type ArrayLikeIterable<T> = ArrayLike<T> & Iterable<T>; // for NodeListOf and Array |
6 | 7 | type ElementArg = Element | string | ArrayLikeIterable<Element> | ReturnType<typeof $>; |
@@ -76,8 +77,8 @@ export function queryElemSiblings<T extends Element>(el: Element, selector = '*' |
76 | 77 |
|
77 | 78 | // it works like jQuery.children: only the direct children are selected |
78 | 79 | export function queryElemChildren<T extends Element>(parent: Element | ParentNode, selector = '*', fn?: ElementsCallback<T>): ArrayLikeIterable<T> { |
79 | | - if (window.vitest) { |
80 | | - // bypass the vitest bug: it doesn't support ":scope >" |
| 80 | + if (isInFrontendUnitTest()) { |
| 81 | + // https://github.com/capricorn86/happy-dom/issues/1620 : ":scope" doesn't work |
81 | 82 | const selected = Array.from<T>(parent.children as any).filter((child) => child.matches(selector)); |
82 | 83 | return applyElemsCallback<T>(selected, fn); |
83 | 84 | } |
@@ -357,6 +358,6 @@ export function addDelegatedEventListener<T extends HTMLElement, E extends Event |
357 | 358 | parent.addEventListener(type, (e: Event) => { |
358 | 359 | const elem = (e.target as HTMLElement).closest(selector); |
359 | 360 | if (!elem) return; |
360 | | - listener(elem as T, e); |
| 361 | + listener(elem as T, e as E); |
361 | 362 | }, options); |
362 | 363 | } |
0 commit comments