/** * A simple test function that mimics the behavior of testing * frameworks. It takes a title, a test function, and an optional flag * to stop testing after this test. The test function receives an * `expect` function to make assertions. * * @param {string} title - The title of the test case. * @param {( * expect: (arg: unknown) => Expect, * ) => void | Promise} fn * - The test function containing assertions. * * @param {boolean} [stopTesting] - If true, no more tests will be run * after this one. * @returns {Promise} A promise that resolves when all * assertions in the test pass, or rejects if any assertion fails. * @url https://pota.quack.uy/use/test */ export function test(title: string, fn: (expect: (arg: unknown) => Expect) => void | Promise, stopTesting?: boolean): Promise; export namespace test { function reset(): void; } export function isProxy(value: unknown): boolean; export function rerenders(): void; export function body(): string; export function head(): string; export function childNodes(node?: Node): number; export function microtask(): Promise; export function macrotask(): Promise; export function sleep(ms?: number): Promise; export function sleepLong(): Promise; /** * Walks past descendant/combinator boundaries (` `, `>`, `+`, `~`, * `,`) to the final compound selector — e.g. `'div input[name="x"]'` * → `'input[name="x"]'`, `'a, b > c'` → `'c'`. * * @template {string} S * @typedef {S extends `${string} ${infer R}` * ? LastCompound * : S extends `${string}>${infer R}` * ? LastCompound * : S extends `${string}+${infer R}` * ? LastCompound * : S extends `${string}~${infer R}` * ? LastCompound * : S extends `${string},${infer R}` * ? LastCompound * : S} LastCompound */ /** * Extracts the tag portion of a compound selector — everything before * the first `[`, `.`, `#`, or `:`. `'input[name="x"]'` → `'input'`, * `'button.primary'` → `'button'`, `'input'` → `'input'`. * * @template {string} S * @typedef {S extends `${infer T}[${string}` * ? T * : S extends `${infer T}.${string}` * ? T * : S extends `${infer T}#${string}` * ? T * : S extends `${infer T}:${string}` * ? T * : S} CompoundTag */ /** * Walks the selector to its last compound, then extracts the tag. For * `'div input[name="x"]'` this resolves to `'input'`; for `'.foo'` it * resolves to `'.foo'` (no tag). * * @template {string} S * @typedef {CompoundTag>} SelectorTag */ /** * Resolves a CSS selector string to its element type, extracting the * leading tag. Falls back to `HTMLElement` when the prefix is not a * known tag name (e.g. class/id-only selectors). * * @template {string} S * @typedef {SelectorTag extends keyof HTMLElementTagNameMap * ? HTMLElementTagNameMap[SelectorTag] * : SelectorTag extends keyof SVGElementTagNameMap * ? SVGElementTagNameMap[SelectorTag] * : SelectorTag extends keyof MathMLElementTagNameMap * ? MathMLElementTagNameMap[SelectorTag] * : HTMLElement} SelectorElement */ /** * Shorthand for `document.querySelector`. Infers the element type * from the selector's leading tag, so `$('input')`, * `$('input[name="x"]')`, and `$('input.foo')` all return * `HTMLInputElement | null`. Pass an explicit element type as a type * parameter to override: `$('.my-class')`. * * @type {{ * ( * selector: S, * node?: Document | HTMLElement, * ): SelectorElement | null * ( * selector: string, * node?: Document | HTMLElement, * ): E | null * }} * @url https://pota.quack.uy/use/test/$ */ export const $: { (selector: S, node?: Document | HTMLElement): SelectorElement | null; (selector: string, node?: Document | HTMLElement): E | null; }; /** * Shorthand for `document.querySelectorAll`, spread into an array so * callers get `Array` methods (`map`, `filter`, etc.). Infers the * element type from the selector's leading tag (see `$`). * * @type {{ * ( * selector: S, * node?: Document | HTMLElement, * ): SelectorElement[] * ( * selector: string, * node?: Document | HTMLElement, * ): E[] * }} * @url https://pota.quack.uy/use/test/$$ */ export const $$: { (selector: S, node?: Document | HTMLElement): SelectorElement[]; (selector: string, node?: Document | HTMLElement): E[]; }; /** * Walks past descendant/combinator boundaries (` `, `>`, `+`, `~`, * `,`) to the final compound selector — e.g. `'div input[name="x"]'` * → `'input[name="x"]'`, `'a, b > c'` → `'c'`. */ export type LastCompound = S extends `${string} ${infer R}` ? LastCompound : S extends `${string}>${infer R}` ? LastCompound : S extends `${string}+${infer R}` ? LastCompound : S extends `${string}~${infer R}` ? LastCompound : S extends `${string},${infer R}` ? LastCompound : S; /** * Extracts the tag portion of a compound selector — everything before * the first `[`, `.`, `#`, or `:`. `'input[name="x"]'` → `'input'`, * `'button.primary'` → `'button'`, `'input'` → `'input'`. */ export type CompoundTag = S extends `${infer T}[${string}` ? T : S extends `${infer T}.${string}` ? T : S extends `${infer T}#${string}` ? T : S extends `${infer T}:${string}` ? T : S; /** * Walks the selector to its last compound, then extracts the tag. For * `'div input[name="x"]'` this resolves to `'input'`; for `'.foo'` it * resolves to `'.foo'` (no tag). */ export type SelectorTag = CompoundTag>; /** * Resolves a CSS selector string to its element type, extracting the * leading tag. Falls back to `HTMLElement` when the prefix is not a * known tag name (e.g. class/id-only selectors). */ export type SelectorElement = SelectorTag extends keyof HTMLElementTagNameMap ? HTMLElementTagNameMap[SelectorTag] : SelectorTag extends keyof SVGElementTagNameMap ? SVGElementTagNameMap[SelectorTag] : SelectorTag extends keyof MathMLElementTagNameMap ? MathMLElementTagNameMap[SelectorTag] : HTMLElement; //# sourceMappingURL=test.d.ts.map