Archived
1
0
Fork 0
This repository has been archived on 2024-07-25. You can view files and clone it, but cannot push or open issues or pull requests.
paren/core/node.test.ts

40 lines
990 B
TypeScript
Raw Permalink Normal View History

2022-05-22 00:03:48 +03:00
import { assertEquals, assertInstanceOf } from "testing/asserts.ts";
2022-05-22 00:26:32 +03:00
import { Elem, Fragment, TextNode } from "./node.ts";
2022-05-22 00:03:48 +03:00
Deno.test({
name: "should create text node from string",
fn: () => {
const sourceText = "hello world";
const tn = new TextNode(sourceText);
assertInstanceOf(tn, TextNode);
assertEquals(tn.innerText, sourceText);
},
});
Deno.test({
name: "should create fragment from array",
fn: () => {
const hello = new TextNode("hello");
const world = new TextNode("world");
const frag = new Fragment([hello, world]);
assertInstanceOf(frag, Fragment);
assertEquals(frag.children, [hello, world]);
},
});
Deno.test({
name: "should create element",
fn: () => {
const child = new Elem("p", {}, [new TextNode("hello world")]);
const el = new Elem("div", { class: "hello" }, [child]);
assertEquals(el.tagName, "div");
assertEquals(el.attrs, { class: "hello" });
assertEquals(el.children, [child]);
},
});