import { assertEquals } from "testing/asserts.ts"; import { E, F, TextNode } from "../core/node.ts"; import { StrRenderer } from "./str.ts"; Deno.test({ name: "should render text node", fn: () => { const tn = new TextNode("hello world"); const ren = new StrRenderer(); const res = ren.render(tn); assertEquals(res, "hello world"); }, }); Deno.test({ name: "should render element", fn: () => { const el = E("p", [], "hello world"); const ren = new StrRenderer(); const res = ren.render(el); assertEquals(res, "
hello world
"); }, }); Deno.test({ name: "should render empty fragment as empty string", fn: () => { const frag = F([]); const ren = new StrRenderer(); const res = ren.render(frag); assertEquals(res, ""); }, }); Deno.test({ name: "should render fragment", fn: () => { const frag = F([ "hello world", E("div", { class: "hello" }), E("p", [], "world"), ]); const ren = new StrRenderer(); const res = ren.render(frag); assertEquals(res, 'hello worldworld
'); }, }); Deno.test({ name: "should recursive render elements", fn: () => { const layout = E("body", [], [ E("div", { id: "root" }, [ E("p", [], "hello world"), ]), ]); const ren = new StrRenderer(); const res = ren.render(layout); assertEquals(res, 'hello world
hello world