1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-05 01:57:20 +00:00

Bypass vitest bug (#32647)

This commit is contained in:
wxiaoguang
2024-11-26 23:10:45 +08:00
committed by GitHub
parent 88f5d33ab2
commit 722e703c6b
2 changed files with 12 additions and 1 deletions

View File

@ -76,6 +76,11 @@ export function queryElemSiblings<T extends Element>(el: Element, selector = '*'
// it works like jQuery.children: only the direct children are selected
export function queryElemChildren<T extends Element>(parent: Element | ParentNode, selector = '*', fn?: ElementsCallback<T>): ArrayLikeIterable<T> {
if (window.vitest) {
// bypass the vitest bug: it doesn't support ":scope >"
const selected = Array.from<T>(parent.children as any).filter((child) => child.matches(selector));
return applyElemsCallback<T>(selected, fn);
}
return applyElemsCallback<T>(parent.querySelectorAll(`:scope > ${selector}`), fn);
}