Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

joi.bind yields any() methods not fully bound #1691

Closed
shellscape opened this issue Dec 28, 2018 · 2 comments
Closed

joi.bind yields any() methods not fully bound #1691

shellscape opened this issue Dec 28, 2018 · 2 comments
Labels
bug Bug or defect
Milestone

Comments

@shellscape
Copy link

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] }
@Marsup Marsup closed this as completed in be992bd Dec 28, 2018
@Marsup Marsup added the bug Bug or defect label Dec 28, 2018
@Marsup Marsup self-assigned this Dec 28, 2018
@Marsup Marsup added this to the 14.3.1 milestone Dec 28, 2018
@shellscape
Copy link
Author

Thanks for jumping on this so quickly!

@lock
Copy link

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug or defect
Projects
None yet
Development

No branches or pull requests

2 participants