Skip to content

Synchronous schema.validate fails if called with options #884

@timelesshaze

Description

@timelesshaze

Context

  • node version: v4.3.0 and v4.4.4
  • joi version: 8.1.0 and 9.0.0-0
  • environment (node, browser): node
  • used with (hapi, standalone, ...): standalone
  • any other relevant information: none

What are you trying to achieve or the steps to reproduce ?

Call the validate function on the schema directly, without specifying a callback, but supplying an options object.

const Joi = require('joi');
const schema = Joi.any();
// Works
Joi.validate('test', { presence: 'optional' });
// Works
schema.validate('test');
// Throws
schema.validate('test', { presence: 'optional' });

Which result you had ?

I get the following error message:

joi/lib/any.js:666
return callback(errors, result.value);
^
TypeError: callback is not a function
at internals.Any.applyFunctionToChildren.internals.Any.validate (/tmp/testapp/node_modules/joi/lib/any.js:666:16)

What did you expect ?

The validate function should work the same way in both cases (Joi.validate and schema.validate).

Metadata

Metadata

Assignees

Labels

featureNew functionality or improvement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions