diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-07-16 12:15:32 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2023-07-16 12:15:32 -0300 |
commit | c5a341835898219602c7f2237f9ddfa7f749ceeb (patch) | |
tree | 4b188fc05b0d2489914283e6d78eb3ade0e40615 /test/unit | |
parent | e1a0a73caed1ecff81630a53cd59c05ded509878 (diff) |
test: html: incorporate {strict,sparse}ArrayOf tests
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/util/html.js | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/test/unit/util/html.js b/test/unit/util/html.js index 3931b297..9b30aeb3 100644 --- a/test/unit/util/html.js +++ b/test/unit/util/html.js @@ -831,20 +831,26 @@ t.test(`Template - slot value errors`, t => { const template2 = html.template({ slots: { - arrayOfStrings: { - validate: v => v.arrayOf(v.isString), + strictArrayOfStrings: { + validate: v => v.strictArrayOf(v.isString), default: `Array Of Strings Fallback`.split(' '), }, + sparseArrayOfStrings: { + validate: v => v.sparseArrayOf(v.isString), + default: ['sparse', null, false, 'strings'], + }, + arrayOfHTML: { - validate: v => v.arrayOf(v.isHTML), + validate: v => v.strictArrayOf(v.isHTML), default: [], }, }, content: slots => html.tag('p', [ - html.tag('strong', slots.arrayOfStrings), + html.tag('strong', slots.strictArrayOfStrings), + `sparseArrayOfStrings length: ${slots.sparseArrayOfStrings.length}`, `arrayOfHTML length: ${slots.arrayOfHTML.length}`, ]), }); @@ -853,7 +859,8 @@ t.test(`Template - slot value errors`, t => { strictlyThrows(t, () => template2.setSlots({ - arrayOfStrings: ['you got it', 'pingas', 0xdeadbeef], + strictArrayOfStrings: ['you got it', 'pingas', 0xdeadbeef], + sparseArrayOfStrings: ['you got it', null, false, 'pingas'], arrayOfHTML: [ html.tag('span'), html.template({content: () => 'dog'}), @@ -870,7 +877,7 @@ t.test(`Template - slot value errors`, t => { new AggregateError([ { name: 'AggregateError', - message: /^\(arrayOfStrings\)/, + message: /^\(strictArrayOfStrings\)/, errors: {length: 1}, }, ], `Error validating template slots`)); @@ -886,6 +893,7 @@ t.test(`Template - slot value errors`, t => { `Strings`, `Fallback`, ]), + `sparseArrayOfStrings length: 4`, `arrayOfHTML length: 0`, ]).toString()); }); |