]>
Lady’s Gitweb - Lemon/blob - mod.test.js
1 // 🍋🏷 Lemon ∷ mod.test.js
2 // ====================================================================
4 // Copyright © 2022 Lady [@ Lady’s Computer]..
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/>.
14 } from "./dev-deps.js";
15 import Lemon
from "./mod.js";
18 name
: "Lemon can be used to make a new element.",
20 const elt
= Lemon("xxx")({})``;
21 assertStrictEquals(typeof elt
, "object");
22 assertStrictEquals(elt
.localName
, "xxx");
28 "Lemon can be used to make a new element in a specified document.",
30 const doc
= new DOMImplementation().createDocument(
35 const elt
= Lemon
.call({ document
: doc
}, "xxx")({})``;
36 assertStrictEquals(elt
.ownerDocument
, doc
);
41 name
: "Lemon uses X·H·T·M·L as the default namespace.",
43 const elt
= Lemon("xxx")({})``;
46 "http://www.w3.org/1999/xhtml",
52 name
: "Lemon uses the provided namespace if present.",
54 const elt
= Lemon("xxx", "example:gay")({})``;
55 assertStrictEquals(elt
.namespaceURI
, "example:gay");
60 name
: '`Lemon.◊` can be used in place of `Lemon("◊")`.',
62 const elt
= Lemon
.xxx({})``;
63 assertStrictEquals(typeof elt
, "object");
64 assertStrictEquals(elt
.localName
, "xxx");
67 "http://www.w3.org/1999/xhtml",
69 const customElt
= Lemon
.creamPie({})``;
70 assertStrictEquals(typeof customElt
, "object");
71 assertStrictEquals(customElt
.localName
, "cream-pie");
73 customElt
.namespaceURI
,
74 "http://www.w3.org/1999/xhtml",
80 name
: "Bound Lemons are also proxied.",
82 const doc
= new DOMImplementation().createDocument(
87 const myLemon
= Lemon
.bind({ document
: doc
});
88 const elt
= myLemon
.creamPie({})``;
89 assertStrictEquals(typeof elt
, "object");
90 assertStrictEquals(elt
.localName
, "cream-pie");
91 assertStrictEquals(elt
.ownerDocument
, doc
);
96 name
: "Lemon tags can be destructured.",
98 const { creamPie
, xxx
} = Lemon
;
99 const elt
= xxx({})``;
100 assertStrictEquals(typeof elt
, "object");
101 assertStrictEquals(elt
.localName
, "xxx");
104 "http://www.w3.org/1999/xhtml",
106 const customElt
= creamPie({})``;
107 assertStrictEquals(typeof customElt
, "object");
108 assertStrictEquals(customElt
.localName
, "cream-pie");
110 customElt
.namespaceURI
,
111 "http://www.w3.org/1999/xhtml",
117 name
: "Lemon tags assign attributes.",
119 const elt
= Lemon
.xxx({ "data-🍆": "💦" })``;
120 assertStrictEquals(elt
.getAttribute("data-🍆"), "💦");
125 name
: "Lemon tags can assign attributes with property chaining.",
132 .dataFalse("failure")
136 .dataName("data-name")
137 .dataName("data-name")
140 assertStrictEquals(elt
.getAttribute("class"), "abc def");
141 assertStrictEquals(elt
.getAttribute("data-wet"), "💦");
142 assertStrictEquals(elt
.getAttribute("data-true"), "");
143 assertStrictEquals(elt
.getAttribute("data-hidden"), "");
144 assertStrictEquals(elt
.getAttribute("data-name"), "data-name");
145 assertStrictEquals(elt
.hasAttribute("data-false"), false);
150 name
: "Lemon tags expose their internal state.",
153 Lemon("xxx:yyy", "example:xxx")
157 .dataFalse("failure")
161 .dataName("data-name")
162 .dataName("data-name")
166 assertEquals(eltTag
.attributes
, {
171 "data-name": "data-name",
174 assertStrictEquals(eltTag
.localName
, "yyy");
175 assertStrictEquals(eltTag
.namespaceURI
, "example:xxx");
176 assertStrictEquals(eltTag
.qualifiedName
, "xxx:yyy");
177 assertStrictEquals(eltTag
.ownerDocument
, document
);
180 '<xxx:yyy xmlns:xxx="example:xxx" class="abc def" data-wet="💦" data-true="" hidden="" data-name="data-name" data-extra=""> /* pending data-extra */',
184 '<xxx:yyy xmlns:xxx="example:xxx" class="abc def" data-wet="💦" data-true="" hidden="" data-name="data-name" data-extra="">',
190 name
: "Lemon tags support all kinds of expression.",
192 const elt
= Lemon
.xxx({})` a ${null} b ${Lemon.creamPie(
195 assertStrictEquals(elt
.childNodes
.length
, 3);
196 assertStrictEquals(elt
.childNodes
[0].nodeType
, 3);
197 assertStrictEquals(elt
.childNodes
[0].textContent
, " a b ");
198 assertStrictEquals(elt
.childNodes
[1].nodeType
, 1);
199 assertStrictEquals(elt
.childNodes
[1].localName
, "cream-pie");
200 assertStrictEquals(elt
.childNodes
[1].textContent
, "\\t");
201 assertStrictEquals(elt
.childNodes
[2].nodeType
, 3);
202 assertStrictEquals(elt
.childNodes
[2].textContent
, " c ");
207 name
: "Lemon tags normalize even nested nodes.",
209 const notNormal
= document
.createElement("i");
210 notNormal
.appendChild(document
.createTextNode(" a "));
211 notNormal
.appendChild(document
.createTextNode(" b "));
212 assertStrictEquals(notNormal
.childNodes
.length
, 2);
213 const elt
= Lemon
.xxx({})`${notNormal}`;
214 assertStrictEquals(elt
.childNodes
[0].nodeType
, 1);
215 assertStrictEquals(elt
.childNodes
[0].childNodes
.length
, 1);
217 elt
.childNodes
[0].childNodes
[0].textContent
,
This page took 0.071819 seconds and 5 git commands to generate.