Closed
Description
Context
- node version: 4.4.3
- joi version: 9.0.0-2 (master at time of testing)
- environment (node, browser): node
- used with (hapi, standalone, ...): standalone
- any other relevant information: Example at https://github.com/nlindley/joi-sparse-empty-test
What are you trying to achieve or the steps to reproduce ?
When marking an array as sparse(false)
, and items()
has a schema that uses empty()
, there is no error.
const schema = Joi.array().items(Joi.object().empty({})).sparse(false);
const data = [{a: 1}, {}, {c: 3}];
schema.validate(data);
Which result you had ?
{ error: null, value: [{a: 1 }, undefined, { c: 3 }] }
What did you expect ?
{ error:
{ [ValidationError: "value" must not be a sparse array]
isJoi: true,
name: 'ValidationError',
details: [ [Object] ],
_object: [ [Object], undefined, [Object] ],
annotate: [Function] },
value: [ { a: 1 }, undefined, { c: 3 } ] }