]> Lady’s Gitweb - Lemon/blob - mod.test.js
Initial commit
[Lemon] / mod.test.js
1 // 🍋🏷 Lemon ∷ mod.test.js
2 // ====================================================================
3 //
4 // Copyright © 2022 Lady [@ Lady’s Computer]..
5 //
6 // This Source Code Form is subject to the terms of the Mozilla Public
7 // License, v. 2.0. If a copy of the MPL was not distributed with this
8 // file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
9
10 import { assertStrictEquals } from "./dev-deps.js";
11 import Lemon from "./mod.js";
12
13 Deno.test({
14 name: "Lemon can be used to make a new element.",
15 fn: () => {
16 const elt = Lemon("xxx")({})``;
17 assertStrictEquals(typeof elt, "object");
18 assertStrictEquals(elt.localName, "xxx");
19 },
20 });
21
22 Deno.test({
23 name: "Lemon uses X·H·T·M·L as the default namespace.",
24 fn: () => {
25 const elt = Lemon("xxx")({})``;
26 assertStrictEquals(
27 elt.namespaceURI,
28 "http://www.w3.org/1999/xhtml",
29 );
30 },
31 });
32
33 Deno.test({
34 name: "Lemon uses the provided namespace if present.",
35 fn: () => {
36 const elt = Lemon("xxx", "example:gay")({})``;
37 assertStrictEquals(elt.namespaceURI, "example:gay");
38 },
39 });
40
41 Deno.test({
42 name: '`Lemon.◊` can be used in place of `Lemon("◊")`.',
43 fn: () => {
44 const elt = Lemon.xxx({})``;
45 assertStrictEquals(typeof elt, "object");
46 assertStrictEquals(elt.localName, "xxx");
47 assertStrictEquals(
48 elt.namespaceURI,
49 "http://www.w3.org/1999/xhtml",
50 );
51 const customElt = Lemon.creamPie({})``;
52 assertStrictEquals(typeof customElt, "object");
53 assertStrictEquals(customElt.localName, "cream-pie");
54 assertStrictEquals(
55 customElt.namespaceURI,
56 "http://www.w3.org/1999/xhtml",
57 );
58 },
59 });
60
61 Deno.test({
62 name: "Lemon tags can be destructured.",
63 fn: () => {
64 const { creamPie, xxx } = Lemon;
65 const elt = xxx({})``;
66 assertStrictEquals(typeof elt, "object");
67 assertStrictEquals(elt.localName, "xxx");
68 assertStrictEquals(
69 elt.namespaceURI,
70 "http://www.w3.org/1999/xhtml",
71 );
72 const customElt = creamPie({})``;
73 assertStrictEquals(typeof customElt, "object");
74 assertStrictEquals(customElt.localName, "cream-pie");
75 assertStrictEquals(
76 customElt.namespaceURI,
77 "http://www.w3.org/1999/xhtml",
78 );
79 },
80 });
81
82 Deno.test({
83 name: "Lemon tags assign attributes.",
84 fn: () => {
85 const elt = Lemon.xxx({ "data-🍆": "💦" })``;
86 assertStrictEquals(elt.getAttribute("data-🍆"), "💦");
87 },
88 });
89
90 Deno.test({
91 name: "Lemon tags support all kinds of expression.",
92 fn: () => {
93 const elt = Lemon.xxx({})` a ${null} b ${Lemon.creamPie({})
94 `\t`}${" c "}`;
95 assertStrictEquals(elt.childNodes.length, 3);
96 assertStrictEquals(elt.childNodes[0].nodeType, 3);
97 assertStrictEquals(elt.childNodes[0].textContent, " a b ");
98 assertStrictEquals(elt.childNodes[1].nodeType, 1);
99 assertStrictEquals(elt.childNodes[1].localName, "cream-pie");
100 assertStrictEquals(elt.childNodes[1].textContent, "\\t");
101 assertStrictEquals(elt.childNodes[2].nodeType, 3);
102 assertStrictEquals(elt.childNodes[2].textContent, " c ");
103 },
104 });
105
106 Deno.test({
107 name: "Lemon tags normalize even nested nodes.",
108 fn: () => {
109 const notNormal = document.createElement("i");
110 notNormal.appendChild(document.createTextNode(" a "));
111 notNormal.appendChild(document.createTextNode(" b "));
112 assertStrictEquals(notNormal.childNodes.length, 2);
113 const elt = Lemon.xxx({})`${notNormal}`;
114 assertStrictEquals(elt.childNodes[0].nodeType, 1);
115 assertStrictEquals(elt.childNodes[0].childNodes.length, 1);
116 assertStrictEquals(
117 elt.childNodes[0].childNodes[0].textContent,
118 " a b ",
119 );
120 },
121 });
This page took 0.179619 seconds and 5 git commands to generate.