// jsdom 測試輔助:建立 DOM 並把必要全域掛上,再回傳 document。 // 注入結構正確性可於 jsdom 驗證;版面(justify/擠壓量/行端)須瀏覽器目視。 import { JSDOM } from "jsdom"; /** * 建立一個帶 body 內容之 jsdom,並把 document / NodeFilter / Node 掛到 * globalThis(dom.ts 之 createJz 用全域 document)。回傳 { dom, document }。 */ export function setupDom(bodyHtml = "") { const dom = new JSDOM( "" + bodyHtml + "", ); globalThis.document = dom.window.document; globalThis.NodeFilter = dom.window.NodeFilter; globalThis.Node = dom.window.Node; globalThis.window = dom.window; return { dom, document: dom.window.document }; } /** 計算 root 下某 tag(大寫)之元素數。 */ export function countTag(root, tag) { return root.querySelectorAll(tag).length; }