]>
Lady’s Gitweb - Lemon/blob - mod.test.js
8af8f73901c351b89b97423a951e0199f99d1355
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
, DOMImplementation
} 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");
24 "Lemon can be used to make a new element in a specified document.",
26 const doc
= new DOMImplementation().createDocument(
31 const elt
= Lemon
.call({ document
: doc
}, "xxx")({})``;
32 assertStrictEquals(elt
.ownerDocument
, doc
);
37 name
: "Lemon uses X·H·T·M·L as the default namespace.",
39 const elt
= Lemon("xxx")({})``;
42 "http://www.w3.org/1999/xhtml",
48 name
: "Lemon uses the provided namespace if present.",
50 const elt
= Lemon("xxx", "example:gay")({})``;
51 assertStrictEquals(elt
.namespaceURI
, "example:gay");
56 name
: '`Lemon.◊` can be used in place of `Lemon("◊")`.',
58 const elt
= Lemon
.xxx({})``;
59 assertStrictEquals(typeof elt
, "object");
60 assertStrictEquals(elt
.localName
, "xxx");
63 "http://www.w3.org/1999/xhtml",
65 const customElt
= Lemon
.creamPie({})``;
66 assertStrictEquals(typeof customElt
, "object");
67 assertStrictEquals(customElt
.localName
, "cream-pie");
69 customElt
.namespaceURI
,
70 "http://www.w3.org/1999/xhtml",
76 name
: "Bound Lemons are also proxied.",
78 const doc
= new DOMImplementation().createDocument(
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
);
92 name
: "Lemon tags can be destructured.",
94 const { creamPie
, xxx
} = Lemon
;
95 const elt
= xxx({})``;
96 assertStrictEquals(typeof elt
, "object");
97 assertStrictEquals(elt
.localName
, "xxx");
100 "http://www.w3.org/1999/xhtml",
102 const customElt
= creamPie({})``;
103 assertStrictEquals(typeof customElt
, "object");
104 assertStrictEquals(customElt
.localName
, "cream-pie");
106 customElt
.namespaceURI
,
107 "http://www.w3.org/1999/xhtml",
113 name
: "Lemon tags assign attributes.",
115 const elt
= Lemon
.xxx({ "data-🍆": "💦" })``;
116 assertStrictEquals(elt
.getAttribute("data-🍆"), "💦");
121 name
: "Lemon tags support all kinds of expression.",
123 const elt
= Lemon
.xxx({})` a ${null} b ${Lemon.creamPie(
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 ");
138 name
: "Lemon tags normalize even nested nodes.",
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);
148 elt
.childNodes
[0].childNodes
[0].textContent
,
This page took 0.099689 seconds and 3 git commands to generate.