import { escapeHtml, html, mount, raw } from "../dist/js/dom.js"; import { assert, equal, test, throws } from "./harness.js"; test("dom: escapes markup in interpolated text", () => { equal( String(html`

${""}

`), "

<script>alert(1)</script>

", ); }); test("dom: escapes quotes so values cannot break out of attributes", () => { const out = String(html`x`); assert(!out.includes('" onmouseover'), `attribute escaped: ${out}`); equal(escapeHtml(`&<>"'`), "&<>"'"); }); test("dom: nested templates are not double-escaped", () => { const list = html``; equal(String(list), ""); }); test("dom: plain strings inside arrays are still escaped", () => { equal(String(html`${["", html``]}`), "<b>"); }); test("dom: raw() passes trusted markup through", () => { equal(String(html`

`), ""); }); test("dom: null/undefined render nothing, false and 0 render as text", () => { equal(String(html`[${null}][${undefined}][${false}][${0}]`), "[][][false][0]"); }); test("dom: mount refuses plain strings", async () => { const el = document.createElement("div"); await throws(() => mount(el, ""), /html`/); equal(el.innerHTML, ""); }); test("dom: injected markup never becomes live elements", () => { const el = document.createElement("div"); window.__pwned = false; mount(el, html`

${""}

`); assert(el.querySelector("img") === null, "no element was created"); assert(window.__pwned === false, "no handler ran"); equal(el.textContent, ""); });