X-Git-Url: https://git.ladys.computer/Lemon/blobdiff_plain/0bcf6926ddc22baf9ba097bf644c908ffcf12c3f..3f0fb84f4cb391464680ba600592df3b811e44a8:/mod.test.js?ds=inline diff --git a/mod.test.js b/mod.test.js index 1c950ab..44e2b9e 100644 --- a/mod.test.js +++ b/mod.test.js @@ -7,7 +7,11 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at . -import { assertStrictEquals } from "./dev-deps.js"; +import { + assertEquals, + assertStrictEquals, + DOMImplementation, +} from "./dev-deps.js"; import Lemon from "./mod.js"; Deno.test({ @@ -19,6 +23,20 @@ Deno.test({ }, }); +Deno.test({ + name: + "Lemon can be used to make a new element in a specified document.", + fn: () => { + const doc = new DOMImplementation().createDocument( + null, + "福", + null, + ); + const elt = Lemon.call({ document: doc }, "xxx")({})``; + assertStrictEquals(elt.ownerDocument, doc); + }, +}); + Deno.test({ name: "Lemon uses X·H·T·M·L as the default namespace.", fn: () => { @@ -58,6 +76,22 @@ Deno.test({ }, }); +Deno.test({ + name: "Bound Lemons are also proxied.", + fn: () => { + const doc = new DOMImplementation().createDocument( + null, + "福", + null, + ); + const myLemon = Lemon.bind({ document: doc }); + const elt = myLemon.creamPie({})``; + assertStrictEquals(typeof elt, "object"); + assertStrictEquals(elt.localName, "cream-pie"); + assertStrictEquals(elt.ownerDocument, doc); + }, +}); + Deno.test({ name: "Lemon tags can be destructured.", fn: () => { @@ -87,11 +121,77 @@ Deno.test({ }, }); +Deno.test({ + name: "Lemon tags can assign attributes with property chaining.", + fn: () => { + const elt = ( + Lemon.xxx + .class("abc") + .class("def") + .dataWet("💦") + .dataFalse("failure") + .dataTrue() + .hidden + .hidden + .dataName("data-name") + .dataName("data-name") + .dataFalse(false) + )``; + assertStrictEquals(elt.getAttribute("class"), "abc def"); + assertStrictEquals(elt.getAttribute("data-wet"), "💦"); + assertStrictEquals(elt.getAttribute("data-true"), ""); + assertStrictEquals(elt.getAttribute("data-hidden"), ""); + assertStrictEquals(elt.getAttribute("data-name"), "data-name"); + assertStrictEquals(elt.hasAttribute("data-false"), false); + }, +}); + +Deno.test({ + name: "Lemon tags expose their internal state.", + fn: () => { + const eltTag = ( + Lemon("xxx:yyy", "example:xxx") + .class("abc") + .class("def") + .dataWet("💦") + .dataFalse("failure") + .dataTrue() + .hidden + .hidden + .dataName("data-name") + .dataName("data-name") + .dataFalse(false) + .dataExtra + ); + assertEquals(eltTag.attributes, { + class: "abc def", + "data-wet": "💦", + "data-true": "", + hidden: "", + "data-name": "data-name", + "data-extra": "", + }); + assertStrictEquals(eltTag.localName, "yyy"); + assertStrictEquals(eltTag.namespaceURI, "example:xxx"); + assertStrictEquals(eltTag.qualifiedName, "xxx:yyy"); + assertStrictEquals(eltTag.ownerDocument, document); + assertStrictEquals( + eltTag.name, + '