Última atividade 1 month ago

nr revisou este gist 1 month ago. Ir para a revisão

1 file changed, 20 insertions

expectEl.ts(arquivo criado)

@@ -0,0 +1,20 @@
1 + export 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 +
14 + export 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 + }
Próximo Anterior