]> Lady’s Gitweb - Lemon/blobdiff - mod.test.js
[window] Polyfill top‐level D·O·M interfaces
[Lemon] / mod.test.js
index 8af8f73901c351b89b97423a951e0199f99d1355..44e2b9e150704aed359f2c97decc43955b214118 100644 (file)
@@ -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 <https://mozilla.org/MPL/2.0/>.
 
-import { assertStrictEquals, DOMImplementation } from "./dev-deps.js";
+import {
+  assertEquals,
+  assertStrictEquals,
+  DOMImplementation,
+} from "./dev-deps.js";
 import Lemon from "./mod.js";
 
 Deno.test({
@@ -117,6 +121,71 @@ 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,
+      '<xxx:yyy xmlns:xxx="example:xxx" class="abc def" data-wet="💦" data-true="" hidden="" data-name="data-name" data-extra=""> /* pending data-extra */',
+    );
+    assertStrictEquals(
+      eltTag().name,
+      '<xxx:yyy xmlns:xxx="example:xxx" class="abc def" data-wet="💦" data-true="" hidden="" data-name="data-name" data-extra="">',
+    );
+  },
+});
+
 Deno.test({
   name: "Lemon tags support all kinds of expression.",
   fn: () => {
This page took 0.054311 seconds and 4 git commands to generate.