import { expect, test } from "vitest";
import { Fragment, RawHtml, renderHtml } from "./html_render.ts";
test("HTML Render", () => {
expect(
renderHtml({
name: "b",
body: "hello",
}),
).toEqual(`hello`);
expect(
renderHtml({
name: "a",
attrs: {
href: "https://example.com",
},
body: "hello",
}),
).toEqual(`hello`);
expect(
renderHtml({
name: "span",
body: "<>",
}),
).toEqual(`<>`);
});
test("RawHtml with string body passes through unescaped", () => {
expect(
renderHtml({
name: RawHtml,
body: 'italic & "quoted"',
}),
).toEqual('italic & "quoted"');
});
test("RawHtml with array body passes strings through unescaped", () => {
expect(
renderHtml({
name: RawHtml,
body: ["bold", { name: "i", body: "normal" }],
}),
).toEqual("boldnormal");
});
test("Void elements have no closing tag", () => {
expect(
renderHtml({
name: "img",
attrs: { src: "test.png", alt: "" },
body: "",
}),
).toEqual('
');
expect(
renderHtml({
name: "IMG",
attrs: { src: "test.png" },
body: "",
}),
).toEqual('
');
expect(
renderHtml({
name: "br",
body: "",
}),
).toEqual("
");
});
test("Fragment renders children without wrapper", () => {
expect(
renderHtml({
name: Fragment,
body: [
{ name: "b", body: "one" },
{ name: "i", body: "two" },
],
}),
).toEqual("onetwo");
});