@@ -696,6 +696,60 @@ describe('array', () => {
696
696
] , done ) ;
697
697
} ) ;
698
698
699
+ it ( 'errors on undefined value after validation' , ( done ) => {
700
+
701
+ const schema = Joi . array ( ) . items ( Joi . object ( ) . empty ( { } ) ) ;
702
+
703
+ Helper . validate ( schema , [
704
+ [ [ { a : 1 } , { } , { c : 3 } ] , false , null , '"value" must not be a sparse array' ]
705
+ ] , done ) ;
706
+ } ) ;
707
+
708
+ it ( 'errors on undefined value after validation with abortEarly false' , ( done ) => {
709
+
710
+ const schema = Joi . array ( ) . items ( Joi . object ( ) . empty ( { } ) ) . options ( { abortEarly : false } ) ;
711
+
712
+ Helper . validate ( schema , [
713
+ [ [ { a : 1 } , { } , 3 ] , false , null , '"value" must not be a sparse array. "value" at position 2 fails because ["2" must be an object]' ]
714
+ ] , done ) ;
715
+ } ) ;
716
+
717
+ it ( 'errors on undefined value after validation with required' , ( done ) => {
718
+
719
+ const schema = Joi . array ( ) . items ( Joi . object ( ) . empty ( { } ) . required ( ) ) ;
720
+
721
+ Helper . validate ( schema , [
722
+ [ [ { } , { c : 3 } ] , false , null , '"value" must not be a sparse array' ]
723
+ ] , done ) ;
724
+ } ) ;
725
+
726
+ it ( 'errors on undefined value after validation with required and abortEarly false' , ( done ) => {
727
+
728
+ const schema = Joi . array ( ) . items ( Joi . object ( ) . empty ( { } ) . required ( ) ) . options ( { abortEarly : false } ) ;
729
+
730
+ Helper . validate ( schema , [
731
+ [ [ { } , 3 ] , false , null , '"value" must not be a sparse array. "value" at position 1 fails because ["1" must be an object]' ]
732
+ ] , done ) ;
733
+ } ) ;
734
+
735
+ it ( 'errors on undefined value after validation with ordered' , ( done ) => {
736
+
737
+ const schema = Joi . array ( ) . ordered ( Joi . object ( ) . empty ( { } ) ) ;
738
+
739
+ Helper . validate ( schema , [
740
+ [ [ { } ] , false , null , '"value" must not be a sparse array' ]
741
+ ] , done ) ;
742
+ } ) ;
743
+
744
+ it ( 'errors on undefined value after validation with ordered and abortEarly false' , ( done ) => {
745
+
746
+ const schema = Joi . array ( ) . ordered ( Joi . object ( ) . empty ( { } ) . required ( ) ) . options ( { abortEarly : false } ) ;
747
+
748
+ Helper . validate ( schema , [
749
+ [ [ { } , 3 ] , false , null , '"value" must not be a sparse array. "value" at position 1 fails because array must contain at most 1 items' ]
750
+ ] , done ) ;
751
+ } ) ;
752
+
699
753
it ( 'validates on undefined value with sparse' , ( done ) => {
700
754
701
755
const schema = Joi . array ( ) . items ( Joi . number ( ) ) . sparse ( ) ;
@@ -706,6 +760,33 @@ describe('array', () => {
706
760
] , done ) ;
707
761
} ) ;
708
762
763
+ it ( 'validates on undefined value after validation' , ( done ) => {
764
+
765
+ const schema = Joi . array ( ) . items ( Joi . object ( ) . empty ( { } ) ) . sparse ( ) ;
766
+
767
+ Helper . validate ( schema , [
768
+ [ [ { a : 1 } , { } , { c : 3 } ] , true , null , [ { a : 1 } , undefined , { c : 3 } ] ]
769
+ ] , done ) ;
770
+ } ) ;
771
+
772
+ it ( 'validates on undefined value after validation with required' , ( done ) => {
773
+
774
+ const schema = Joi . array ( ) . items ( Joi . object ( ) . empty ( { } ) . required ( ) ) . sparse ( ) ;
775
+
776
+ Helper . validate ( schema , [
777
+ [ [ { a : 1 } , { } , { c : 3 } ] , true , null , [ { a : 1 } , undefined , { c : 3 } ] ]
778
+ ] , done ) ;
779
+ } ) ;
780
+
781
+ it ( 'validates on undefined value after validation with ordered' , ( done ) => {
782
+
783
+ const schema = Joi . array ( ) . ordered ( Joi . object ( ) . empty ( { } ) ) . sparse ( ) ;
784
+
785
+ Helper . validate ( schema , [
786
+ [ [ { } ] , true , null , [ undefined ] ]
787
+ ] , done ) ;
788
+ } ) ;
789
+
709
790
it ( 'switches the sparse flag' , ( done ) => {
710
791
711
792
const schema = Joi . array ( ) . sparse ( ) ;
0 commit comments