@@ -247,36 +247,66 @@ describe('AJV6Validator', () => {
247
247
describe ( 'Custom validate function' , ( ) => {
248
248
let errors : RJSFValidationError [ ] ;
249
249
let errorSchema : ErrorSchema ;
250
+ describe ( 'formData is provided' , ( ) => {
251
+ beforeAll ( ( ) => {
252
+ const schema : RJSFSchema = {
253
+ type : 'object' ,
254
+ required : [ 'pass1' , 'pass2' ] ,
255
+ properties : {
256
+ pass1 : { type : 'string' } ,
257
+ pass2 : { type : 'string' } ,
258
+ foo : { type : 'array' , items : { type : 'string' } } // Adding an array for test coverage
259
+ } ,
260
+ } ;
250
261
251
- beforeAll ( ( ) => {
252
- const schema : RJSFSchema = {
253
- type : 'object' ,
254
- required : [ 'pass1' , 'pass2' ] ,
255
- properties : {
256
- pass1 : { type : 'string' } ,
257
- pass2 : { type : 'string' } ,
258
- foo : { type : 'array' , items : { type : 'string' } } // Adding an array for test coverage
259
- } ,
260
- } ;
261
-
262
- const validate = ( formData : any , errors : FormValidation < any > ) => {
263
- if ( formData . pass1 !== formData . pass2 ) {
264
- errors . pass2 ! . addError ( 'passwords don`t match.' ) ;
265
- }
266
- return errors ;
267
- } ;
268
- const formData = { pass1 : 'a' , pass2 : 'b' , foo : [ 'a' ] } ;
269
- const result = validator . validateFormData ( formData , schema , validate ) ;
270
- errors = result . errors ;
271
- errorSchema = result . errorSchema ;
272
- } ) ;
273
- it ( 'should return an error list' , ( ) => {
274
- expect ( errors ) . toHaveLength ( 1 ) ;
275
- expect ( errors [ 0 ] . stack ) . toEqual ( 'pass2: passwords don`t match.' ) ;
262
+ const validate = ( formData : any , errors : FormValidation < any > ) => {
263
+ if ( formData . pass1 !== formData . pass2 ) {
264
+ errors . pass2 ! . addError ( 'passwords don`t match.' ) ;
265
+ }
266
+ return errors ;
267
+ } ;
268
+ const formData = { pass1 : 'a' , pass2 : 'b' , foo : [ 'a' ] } ;
269
+ const result = validator . validateFormData ( formData , schema , validate ) ;
270
+ errors = result . errors ;
271
+ errorSchema = result . errorSchema ;
272
+ } ) ;
273
+ it ( 'should return an error list' , ( ) => {
274
+ expect ( errors ) . toHaveLength ( 1 ) ;
275
+ expect ( errors [ 0 ] . stack ) . toEqual ( 'pass2: passwords don`t match.' ) ;
276
+ } ) ;
277
+ it ( 'should return an errorSchema' , ( ) => {
278
+ expect ( errorSchema . pass2 ! . __errors ) . toHaveLength ( 1 ) ;
279
+ expect ( errorSchema . pass2 ! . __errors ! [ 0 ] ) . toEqual ( 'passwords don`t match.' ) ;
280
+ } ) ;
276
281
} ) ;
277
- it ( 'should return an errorSchema' , ( ) => {
278
- expect ( errorSchema . pass2 ! . __errors ) . toHaveLength ( 1 ) ;
279
- expect ( errorSchema . pass2 ! . __errors ! [ 0 ] ) . toEqual ( 'passwords don`t match.' ) ;
282
+ describe ( 'formData is missing data' , ( ) => {
283
+ beforeAll ( ( ) => {
284
+ const schema : RJSFSchema = {
285
+ type : 'object' ,
286
+ properties : {
287
+ pass1 : { type : 'string' } ,
288
+ pass2 : { type : 'string' } ,
289
+ } ,
290
+ } ;
291
+ const validate = ( formData : any , errors : FormValidation < any > ) => {
292
+ if ( formData . pass1 !== formData . pass2 ) {
293
+ errors . pass2 ! . addError ( 'passwords don`t match.' ) ;
294
+ }
295
+ return errors ;
296
+ } ;
297
+ const formData = { pass1 : 'a' } ;
298
+ const result = validator . validateFormData ( formData , schema , validate ) ;
299
+ errors = result . errors ;
300
+ errorSchema = result . errorSchema ;
301
+ } ) ;
302
+ it ( 'should return an error list' , ( ) => {
303
+ expect ( errors ) . toHaveLength ( 1 ) ;
304
+ expect ( errors [ 0 ] . stack ) . toEqual ( 'pass2: passwords don`t match.' ) ;
305
+ } ) ;
306
+ it ( 'should return an errorSchema' , ( ) => {
307
+ expect ( errorSchema . pass2 ! . __errors ) . toHaveLength ( 1 ) ;
308
+ expect ( errorSchema . pass2 ! . __errors ! [ 0 ] ) . toEqual ( 'passwords don`t match.' ) ;
309
+ } ) ;
280
310
} ) ;
281
311
} ) ;
282
312
describe ( 'Data-Url validation' , ( ) => {
0 commit comments