Naposledy aktivní 1 month ago

Revize 901dae65239cada863d2d02ddbaa2516ecb193ea

expectEl.ts Raw
1export function expectEl<T extends HTMLElement = HTMLElement>(
2 query: string,
3 rootEl: Element | Document = document,
4): T {
5 const el = rootEl.querySelector<T>(query);
6
7 if (!el) {
8 throw new Error(`[expectEl] Can't find \`${query}\` element`);
9 }
10
11 return el;
12}
13
14export function expectEls<T extends HTMLElement = HTMLElement>(
15 query: string,
16 rootEl: Element | Document = document,
17): T[] {
18 const els = rootEl.querySelectorAll<T>(query);
19 return Array.from(els);
20}