Skip to content

Commit 7a79df0

Browse files
GerkinDevMarsup
authored andcommitted
test: add tests and make functions optional
1 parent 610b635 commit 7a79df0

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ declare namespace Joi {
642642
}
643643

644644
interface ExpressionOptions extends ReferenceOptions {
645-
functions: Record<string, (...args: unknown[]) => unknown>
645+
functions?: Record<string, (...args: unknown[]) => unknown>
646646
}
647647

648648
interface StringRegexOptions {

test/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ validOpts = {
6969
messages: {
7070
'any.ref': str,
7171
'string.email': str,
72+
'any.custom': Joi.x('{{.value}}')
7273
},
7374
dateFormat: 'iso',
7475
};
@@ -996,6 +997,8 @@ expr = Joi.expression('{{foo}}', { iterables: true });
996997
expr = Joi.expression('{{foo}}', { map: [['key', 'value']] });
997998
expr = Joi.expression('{{foo}}', { prefix: { local: '%' } });
998999
expr = Joi.expression('{{foo}}', { separator: '_' });
1000+
expr = Joi.expression('{{foo}}', { functions: { foo: (...args) => 'return' } });
1001+
expect.type<string>(Joi.expression('{{foo}}').render(42, {} as Joi.State, {}, {}))
9991002

10001003
expr = Joi.x('{{foo}}');
10011004
expr = Joi.x('{{foo}}', { adjust: (value) => value });
@@ -1005,6 +1008,8 @@ expr = Joi.x('{{foo}}', { iterables: true });
10051008
expr = Joi.x('{{foo}}', { map: [['key', 'value']] });
10061009
expr = Joi.x('{{foo}}', { prefix: { local: '%' } });
10071010
expr = Joi.x('{{foo}}', { separator: '_' });
1011+
expr = Joi.x('{{foo}}', { functions: { foo: (...args) => 'return' } });
1012+
expect.type<string>(Joi.x('{{foo}}').render(42, {} as Joi.State, {}, {}))
10081013

10091014
// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
10101015

0 commit comments

Comments
 (0)