import { test } from "vitest";
import { elementToObject } from "./ast.js";
import { h } from "./index.js";
import { renderDocument, renderElement } from "./render_html.js";
test("basic output", ({ expect }) => {
const input = h.document(h.doctype(), h.html(h.head(h.title("Hello, world!"))));
expect(renderDocument(input)).toBe("
Hello, world!");
});
test("it works", ({ expect }) => {
const a1 = h.a({ href: "https://example.com" }, "Hello, world!");
const a2 = h.a({ class: "link", href: "https://www.example.org" }, "Hello, world!");
expect(a1.children).toStrictEqual(a2.children);
});
test("rendering works", ({ expect }) => {
const p = h.p(h.a({ href: "https://example.com" }, "Hello, world!"), " With some text.");
expect(renderElement(p)).toBe(`Hello, world! With some text.
`);
});
test("it works redux ", ({ expect }) => {
const doc = h.html(
h.head(h.meta({ charset: "utf-8" }), h.title("Hello, world!")),
h.body(h.h1({ class: "blah" }, "Hello, world!")),
);
expect(renderElement(doc)).toBe(
`Hello, world!Hello, world!
`,
);
expect(elementToObject(doc)).toMatchObject({
tag: "html",
attributes: {},
children: [
{
tag: "head",
children: [
{ tag: "meta", attributes: { charset: "utf-8" } },
{ tag: "title", attributes: {}, children: ["Hello, world!"] },
],
},
{
tag: "body",
attributes: {},
children: [{ tag: "h1", attributes: { class: "blah" }, children: ["Hello, world!"] }],
},
],
});
});