]> Lady’s Gitweb - Lemon/blobdiff - mod.test.js
Allow document specification and binding
[Lemon] / mod.test.js
index 1c950ab19b47075b49c9a57186a3414c99d14ef9..8af8f73901c351b89b97423a951e0199f99d1355 100644 (file)
@@ -7,7 +7,7 @@
 // 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 } from "./dev-deps.js";
+import { assertStrictEquals, DOMImplementation } from "./dev-deps.js";
 import Lemon from "./mod.js";
 
 Deno.test({
@@ -19,6 +19,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 +72,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: () => {
@@ -90,8 +120,9 @@ Deno.test({
 Deno.test({
   name: "Lemon tags support all kinds of expression.",
   fn: () => {
-    const elt = Lemon.xxx({})` a ${null} b ${Lemon.creamPie({})
-      `\t`}${" c "}`;
+    const elt = Lemon.xxx({})` a ${null} b ${Lemon.creamPie(
+      {},
+    )`\t`}${" c "}`;
     assertStrictEquals(elt.childNodes.length, 3);
     assertStrictEquals(elt.childNodes[0].nodeType, 3);
     assertStrictEquals(elt.childNodes[0].textContent, " a  b ");
This page took 0.022643 seconds and 4 git commands to generate.