]>
Lady’s Gitweb - Lemon/blob - mod.test.js
1c950ab19b47075b49c9a57186a3414c99d14ef9
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/>.
10 import { assertStrictEquals
} from "./dev-deps.js";
11 import Lemon
from "./mod.js";
14 name
: "Lemon can be used to make a new element.",
16 const elt
= Lemon("xxx")({})``;
17 assertStrictEquals(typeof elt
, "object");
18 assertStrictEquals(elt
.localName
, "xxx");
23 name
: "Lemon uses X·H·T·M·L as the default namespace.",
25 const elt
= Lemon("xxx")({})``;
28 "http://www.w3.org/1999/xhtml",
34 name
: "Lemon uses the provided namespace if present.",
36 const elt
= Lemon("xxx", "example:gay")({})``;
37 assertStrictEquals(elt
.namespaceURI
, "example:gay");
42 name
: '`Lemon.◊` can be used in place of `Lemon("◊")`.',
44 const elt
= Lemon
.xxx({})``;
45 assertStrictEquals(typeof elt
, "object");
46 assertStrictEquals(elt
.localName
, "xxx");
49 "http://www.w3.org/1999/xhtml",
51 const customElt
= Lemon
.creamPie({})``;
52 assertStrictEquals(typeof customElt
, "object");
53 assertStrictEquals(customElt
.localName
, "cream-pie");
55 customElt
.namespaceURI
,
56 "http://www.w3.org/1999/xhtml",
62 name
: "Lemon tags can be destructured.",
64 const { creamPie
, xxx
} = Lemon
;
65 const elt
= xxx({})``;
66 assertStrictEquals(typeof elt
, "object");
67 assertStrictEquals(elt
.localName
, "xxx");
70 "http://www.w3.org/1999/xhtml",
72 const customElt
= creamPie({})``;
73 assertStrictEquals(typeof customElt
, "object");
74 assertStrictEquals(customElt
.localName
, "cream-pie");
76 customElt
.namespaceURI
,
77 "http://www.w3.org/1999/xhtml",
83 name
: "Lemon tags assign attributes.",
85 const elt
= Lemon
.xxx({ "data-🍆": "💦" })``;
86 assertStrictEquals(elt
.getAttribute("data-🍆"), "💦");
91 name
: "Lemon tags support all kinds of expression.",
93 const elt
= Lemon
.xxx({})` a ${null} b ${Lemon.creamPie({})
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 ");
107 name
: "Lemon tags normalize even nested nodes.",
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);
117 elt
.childNodes
[0].childNodes
[0].textContent
,
This page took 0.093622 seconds and 3 git commands to generate.