@@ -129,6 +129,54 @@ describe("Validators", () => {
129
129
} ) ;
130
130
} ) ;
131
131
132
+ describe . only ( "test Validators.array" , ( ) => {
133
+
134
+ let field = {
135
+ required : true ,
136
+ min : 2 ,
137
+ max : 4
138
+ }
139
+
140
+ it ( "should give error if value is null, but field is required" , ( ) => {
141
+ check ( v . array , null , field , 1 ) ;
142
+ } ) ;
143
+
144
+ it ( "should give error if count of items is smaller than min" , ( ) => {
145
+ check ( v . array , [ ] , field , 1 ) ;
146
+ check ( v . array , [ 1 ] , field , 1 ) ;
147
+ check ( v . array , [ "ab" ] , field , 1 ) ;
148
+ check ( v . array , [ true ] , field , 1 ) ;
149
+ } ) ;
150
+
151
+ it ( "should give error if count of items is greater than max" , ( ) => {
152
+ check ( v . array , [ 1 , 2 , 3 , 4 , 5 ] , field , 1 ) ;
153
+ } ) ;
154
+
155
+ it ( "should give error if value is not array" , ( ) => {
156
+ check ( v . array , 123 , field , 1 ) ;
157
+ check ( v . array , true , field , 1 ) ;
158
+ check ( v . array , "John" , field , 1 ) ;
159
+ } ) ;
160
+
161
+ it ( "should not give error" , ( ) => {
162
+ check ( v . array , [ 1 , 4 ] , field , 0 ) ;
163
+ check ( v . array , [ "John" , "Doe" , "Jane" ] , field , 0 ) ;
164
+ check ( v . array , [ true , true , false ] , field , 0 ) ;
165
+ check ( v . array , [ [ 5 ] , [ 3 ] ] , field , 0 ) ;
166
+ } ) ;
167
+
168
+ it ( "should not give error if value is null and field is not required" , ( ) => {
169
+ field . required = false ;
170
+ check ( v . array , null , field , 0 ) ;
171
+ } ) ;
172
+
173
+ it ( "should give error if count of item is smaller than minimum and field is not required" , ( ) => {
174
+ field . required = false ;
175
+ check ( v . array , [ "Foo" ] , field , 1 ) ;
176
+ } ) ;
177
+
178
+ } ) ;
179
+
132
180
describe ( "test Validators.date" , ( ) => {
133
181
134
182
let field = {
0 commit comments