]> Lady’s Gitweb - Lemon/blob - mod.test.js
8af8f73901c351b89b97423a951e0199f99d1355
[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, DOMImplementation } 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:
24 "Lemon can be used to make a new element in a specified document.",
25 fn: () => {
26 const doc = new DOMImplementation().createDocument(
27 null,
28 "福",
29 null,
30 );
31 const elt = Lemon.call({ document: doc }, "xxx")({})``;
32 assertStrictEquals(elt.ownerDocument, doc);
33 },
34 });
35
36 Deno.test({
37 name: "Lemon uses X·H·T·M·L as the default namespace.",
38 fn: () => {
39 const elt = Lemon("xxx")({})``;
40 assertStrictEquals(
41 elt.namespaceURI,
42 "http://www.w3.org/1999/xhtml",
43 );
44 },
45 });
46
47 Deno.test({
48 name: "Lemon uses the provided namespace if present.",
49 fn: () => {
50 const elt = Lemon("xxx", "example:gay")({})``;
51 assertStrictEquals(elt.namespaceURI, "example:gay");
52 },
53 });
54
55 Deno.test({
56 name: '`Lemon.◊` can be used in place of `Lemon("◊")`.',
57 fn: () => {
58 const elt = Lemon.xxx({})``;
59 assertStrictEquals(typeof elt, "object");
60 assertStrictEquals(elt.localName, "xxx");
61 assertStrictEquals(
62 elt.namespaceURI,
63 "http://www.w3.org/1999/xhtml",
64 );
65 const customElt = Lemon.creamPie({})``;
66 assertStrictEquals(typeof customElt, "object");
67 assertStrictEquals(customElt.localName, "cream-pie");
68 assertStrictEquals(
69 customElt.namespaceURI,
70 "http://www.w3.org/1999/xhtml",
71 );
72 },
73 });
74
75 Deno.test({
76 name: "Bound Lemons are also proxied.",
77 fn: () => {
78 const doc = new DOMImplementation().createDocument(
79 null,
80 "福",
81 null,
82 );
83 const myLemon = Lemon.bind({ document: doc });
84 const elt = myLemon.creamPie({})``;
85 assertStrictEquals(typeof elt, "object");
86 assertStrictEquals(elt.localName, "cream-pie");
87 assertStrictEquals(elt.ownerDocument, doc);
88 },
89 });
90
91 Deno.test({
92 name: "Lemon tags can be destructured.",
93 fn: () => {
94 const { creamPie, xxx } = Lemon;
95 const elt = xxx({})``;
96 assertStrictEquals(typeof elt, "object");
97 assertStrictEquals(elt.localName, "xxx");
98 assertStrictEquals(
99 elt.namespaceURI,
100 "http://www.w3.org/1999/xhtml",
101 );
102 const customElt = creamPie({})``;
103 assertStrictEquals(typeof customElt, "object");
104 assertStrictEquals(customElt.localName, "cream-pie");
105 assertStrictEquals(
106 customElt.namespaceURI,
107 "http://www.w3.org/1999/xhtml",
108 );
109 },
110 });
111
112 Deno.test({
113 name: "Lemon tags assign attributes.",
114 fn: () => {
115 const elt = Lemon.xxx({ "data-🍆": "💦" })``;
116 assertStrictEquals(elt.getAttribute("data-🍆"), "💦");
117 },
118 });
119
120 Deno.test({
121 name: "Lemon tags support all kinds of expression.",
122 fn: () => {
123 const elt = Lemon.xxx({})` a ${null} b ${Lemon.creamPie(
124 {},
125 )`\t`}${" c "}`;
126 assertStrictEquals(elt.childNodes.length, 3);
127 assertStrictEquals(elt.childNodes[0].nodeType, 3);
128 assertStrictEquals(elt.childNodes[0].textContent, " a b ");
129 assertStrictEquals(elt.childNodes[1].nodeType, 1);
130 assertStrictEquals(elt.childNodes[1].localName, "cream-pie");
131 assertStrictEquals(elt.childNodes[1].textContent, "\\t");
132 assertStrictEquals(elt.childNodes[2].nodeType, 3);
133 assertStrictEquals(elt.childNodes[2].textContent, " c ");
134 },
135 });
136
137 Deno.test({
138 name: "Lemon tags normalize even nested nodes.",
139 fn: () => {
140 const notNormal = document.createElement("i");
141 notNormal.appendChild(document.createTextNode(" a "));
142 notNormal.appendChild(document.createTextNode(" b "));
143 assertStrictEquals(notNormal.childNodes.length, 2);
144 const elt = Lemon.xxx({})`${notNormal}`;
145 assertStrictEquals(elt.childNodes[0].nodeType, 1);
146 assertStrictEquals(elt.childNodes[0].childNodes.length, 1);
147 assertStrictEquals(
148 elt.childNodes[0].childNodes[0].textContent,
149 " a b ",
150 );
151 },
152 });
This page took 0.099689 seconds and 3 git commands to generate.