@@ -19,6 +19,54 @@ const incorrect_sample = [{
1919 idx : 3
2020} ]
2121
22+ tape . test ( 'should be correctly described' , ( t ) => {
23+ const schema = Joi . array ( ) . items ( {
24+ idx : Joi . number ( ) . integer ( )
25+ } ) . continuous ( 'idx' , 2 ) ;
26+
27+ t . deepEqual ( schema . describe ( ) , {
28+ type : 'array' ,
29+ flags : {
30+ sparse : false ,
31+ comparator : 'idx' ,
32+ startIndex : 2
33+ } ,
34+ options : {
35+ language : {
36+ array : {
37+ continuous_from : 'must be start from {{startIndex}}' ,
38+ continuous_broken : 'should be {{expectedValue}}'
39+ }
40+ }
41+ } ,
42+ rules : [
43+ {
44+ name : 'continuous' ,
45+ arg : {
46+ comparator : 'idx' ,
47+ startIndex : 2
48+ } ,
49+ description : 'idx must be an integer and started continuous from 2'
50+ }
51+ ] ,
52+ items : [
53+ {
54+ type : 'object' ,
55+ children : {
56+ idx : {
57+ type : 'number' ,
58+ invalids : [ Infinity , - Infinity ] ,
59+ rules : [ {
60+ name : 'integer'
61+ } ]
62+ }
63+ }
64+ }
65+ ]
66+ } )
67+ t . end ( )
68+ } )
69+
2270tape . test ( 'fails with invalid comparator' , ( t ) => {
2371 const schema = Joi . array ( ) . items ( {
2472 idx : Joi . number ( ) . integer ( )
@@ -28,15 +76,6 @@ tape.test('fails with invalid comparator', (t) => {
2876 t . end ( )
2977} )
3078
31- // tape.test('fails with invalid startIndex', (t) => {
32- // const schema = Joi.array().items({
33- // idx: Joi.number().integer()
34- // }).continuous('idx', 'a')
35-
36- // t.throws(() => schema.validate(correct_sample), ValidationError, 'startIndex must be a number')
37- // t.end()
38- // })
39-
4079tape . test ( 'fails without startIndex' , ( t ) => {
4180 const schema = Joi . array ( ) . items ( {
4281 idx : Joi . number ( ) . integer ( )
0 commit comments