Files
olivv-cs-ComfyUI-FunPack/app/composer/tests/text.test.js
T
digital-garbage 58193d3f21 composer: the internals, provable with no elements defined
register/zlayer/anchor/motion/density are pure cores over plain data, so most of
the suite runs with no DOM at all; jsdom covers only what is genuinely DOM.
100 tests, zero elements.

These five are why v4 had 11 hand-built modals and 7 hand-built popovers: there
was nothing shared to reuse. register makes an element exist only because a file
defined it; portal gives every overlay one stacking parent; zlayer owns the only
z-index in the app; dismiss keeps one stack so Escape pops the top and not the
modal underneath; anchor measures, flips and clamps once.

Three bugs the tests found: unmount() called removeChild on null when no portal
existed yet, focusables() checked aria-hidden on the element instead of its
ancestors so a hidden subtree stayed tab-reachable, and the density ratios v4
hand-tuned are now derived from the gap they were meant to allow for.
2026-08-28 15:03:19 +03:00

58 lines
1.9 KiB
JavaScript

import test from "node:test";
import assert from "node:assert/strict";
import { setupDom, teardownDom } from "./_dom.js";
import { asText, setText } from "../internals/text.js";
test.beforeEach(() => setupDom());
test.after(() => teardownDom());
test("scalars become text nodes", () => {
assert.equal(asText("hi").nodeType, 3);
assert.equal(asText(42).textContent, "42");
assert.equal(asText(true).textContent, "true");
assert.equal(asText(0).textContent, "0");
assert.equal(asText("").textContent, "");
});
test("null and undefined render as nothing, not as the word", () => {
assert.equal(asText(null).textContent, "");
assert.equal(asText(undefined).textContent, "");
});
test("markup arrives as literal text, never as elements", () => {
const host = document.createElement("div");
host.appendChild(asText('<img src=x onerror="boom()">'));
assert.equal(host.querySelector("img"), null);
assert.equal(host.textContent, '<img src=x onerror="boom()">');
});
test("a DOM node is refused, and the message says why", () => {
const node = document.createElement("span");
assert.throws(() => asText(node), (err) => {
assert.ok(err instanceof TypeError);
assert.match(err.message, /DOM node/);
return true;
});
});
test("objects, arrays and functions are refused", () => {
// Refusing beats escaping: there is no path where markup exists and someone
// forgot to escape it.
for (const bad of [{}, [], () => {}, Symbol("x")]) {
assert.throws(() => asText(bad), TypeError);
}
});
test("non-finite numbers are refused rather than printed", () => {
for (const bad of [NaN, Infinity, -Infinity]) assert.throws(() => asText(bad), TypeError);
});
test("setText replaces content instead of appending", () => {
const host = document.createElement("div");
setText(host, "one");
setText(host, "two");
assert.equal(host.textContent, "two");
assert.equal(host.childNodes.length, 1);
});