From 27a1df82ac455a44965cbcaef3e3bd1765d95942 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 15 Apr 2023 19:35:51 -0300 Subject: html, test: default slots only for null, not falsey values --- test/unit/util/html.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'test/unit') 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(), `r-r-really, me?`); 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(), `123 0 false (length: 0)`); }); t.test(`Template - description errors`, t => { -- cgit 1.3.0-6-gf8a5