« get me outta code hell

html, test: default slots only for null, not falsey values - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/test/unit/util
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-04-15 19:35:51 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-04-15 19:35:51 -0300
commit27a1df82ac455a44965cbcaef3e3bd1765d95942 (patch)
tree047df07887a7d232a818b3c883f4d9a0542286b3 /test/unit/util
parent357015de21e7e427f25b31a2622fb9182ec292e1 (diff)
html, test: default slots only for null, not falsey values
Diffstat (limited to 'test/unit/util')
-rw-r--r--test/unit/util/html.js31
1 files changed, 30 insertions, 1 deletions
diff --git a/test/unit/util/html.js b/test/unit/util/html.js
index 97bc1e5c..6a352a3b 100644
--- a/test/unit/util/html.js
+++ b/test/unit/util/html.js
@@ -498,7 +498,7 @@ t.test(`Tag.toString (custom attributes)`, t => {
 });
 
 t.test(`html.template`, t => {
-  t.plan(10);
+  t.plan(11);
 
   let contentCalls;
 
@@ -544,6 +544,35 @@ t.test(`html.template`, t => {
   t.equal(contentCalls, 1);
   t.equal(template2.toString(), `<sub>r-r-really, me?</sub>`);
   t.equal(contentCalls, 2);
+
+  // 11: slot uses default only for null, not falsey
+
+  const template3 = html.template({
+    slots: {
+      slot1: {type: 'number', default: 123},
+      slot2: {type: 'number', default: 456},
+      slot3: {type: 'boolean', default: true},
+      slot4: {type: 'string', default: 'banana'},
+    },
+
+    content(slots) {
+      return html.tag('span', [
+        slots.slot1,
+        slots.slot2,
+        slots.slot3,
+        `(length: ${slots.slot4.length})`,
+      ].join(' '));
+    },
+  });
+
+  template3.setSlots({
+    slot1: null,
+    slot2: 0,
+    slot3: false,
+    slot4: '',
+  });
+
+  t.equal(template3.toString(), `<span>123 0 false (length: 0)</span>`);
 });
 
 t.test(`Template - description errors`, t => {