Skip to content

Commit 195e4fd

Browse files
committed
test: add tests and make functions optional
1 parent 35d2411 commit 195e4fd

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
@@ -67,6 +67,7 @@ validOpts = {
6767
messages: {
6868
'any.ref': str,
6969
'string.email': str,
70+
'any.custom': Joi.x('{{.value}}')
7071
},
7172
dateFormat: 'iso',
7273
};
@@ -994,6 +995,8 @@ expr = Joi.expression('{{foo}}', { iterables: true });
994995
expr = Joi.expression('{{foo}}', { map: [['key', 'value']] });
995996
expr = Joi.expression('{{foo}}', { prefix: { local: '%' } });
996997
expr = Joi.expression('{{foo}}', { separator: '_' });
998+
expr = Joi.expression('{{foo}}', { functions: { foo: (...args) => 'return' } });
999+
expect.type<string>(Joi.expression('{{foo}}').render(42, {} as Joi.State, {}, {}))
9971000

9981001
expr = Joi.x('{{foo}}');
9991002
expr = Joi.x('{{foo}}', { adjust: (value) => value });
@@ -1003,6 +1006,8 @@ expr = Joi.x('{{foo}}', { iterables: true });
10031006
expr = Joi.x('{{foo}}', { map: [['key', 'value']] });
10041007
expr = Joi.x('{{foo}}', { prefix: { local: '%' } });
10051008
expr = Joi.x('{{foo}}', { separator: '_' });
1009+
expr = Joi.x('{{foo}}', { functions: { foo: (...args) => 'return' } });
1010+
expect.type<string>(Joi.x('{{foo}}').render(42, {} as Joi.State, {}, {}))
10061011

10071012
// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
10081013

0 commit comments

Comments
 (0)