-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
bugBug or defectBug or defect
Milestone
Description
Context
- node version: 10.13.0
- joi version: 14.3.0
- environment (node, browser): Node
- used with (hapi, standalone, ...): standalone
- any other relevant information:
What are you trying to achieve or the steps to reproduce ?
When using joi.bind(), methods are returned as part of the resulting object which are not fully bound and cause subsequent errors:
const { allow, object, validate } = Joi.bind();
const schema = object().keys({
a: [allow(null)]
});
const o = { a: 0 };
console.log(validate(o, schema));The allow method exists on the bound object, but is not bound properly, as the error below is generated. To work around the issue, we must use allow directly from any, which is not the optimal solution.
const { any, object, validate } = Joi.bind();
const schema = object().keys({
a: [any().allow(null)]
});
const o = { a: 0 };
console.log(validate(o, schema));Which result you had ?
/code/webpack/webpack-plugin-serve/node_modules/joi/lib/types/any/index.js:301
const obj = this.clone();
^
TypeError: Cannot read property 'clone' of undefined
at allow (/code/webpack/webpack-plugin-serve/node_modules/joi/lib/types/any/index.js:301:26)
at Object.<anonymous> (/code/webpack/webpack-plugin-serve/s.js:28:7)
What did you expect ?
{ error: null,
value: { a: 0 },
then: [Function: then],
catch: [Function: catch] }
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugBug or defectBug or defect