1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
import * as helper from "./helper";
import CSSselect from "../../src";
import type { Element, Node } from "domhandler";
let document = loadDoc();
export function loadDoc(): helper.SimpleDocument {
return (document = helper.getDocument("sizzle.html"));
}
/**
* Returns an array of elements with the given IDs
* @example q("main", "foo", "bar")
* @result [<div id="main">, <span id="foo">, <input id="bar">]
*/
export function q(...ids: string[]): Element[] {
return ids.map((id) => document.getElementById(id));
}
/**
* Asserts that a select matches the given IDs
* @param selector - Selector
* @param expectedIds - Array of ids to construct what is expected
* @param context - Root of the current search.
* @example t("Check for something", "//[a]", ["foo", "baar"]);
* @returns `true` iff the selector produces the expected elements.
*/
export function t(
selector: string,
expectedIds: string[],
context: Node[] | Node | null = document
): void {
const actual = CSSselect(selector, context) as Element[];
const actualIds = actual.map((e) => e.attribs.id);
// Should not contain falsy values
expect(actualIds).toStrictEqual(expectedIds);
}
const xmlDoc = helper.getDOMFromPath("fries.xml", {
xmlMode: true,
});
export function createWithFriesXML(): Node[] {
return xmlDoc;
}
|