File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -586,6 +586,34 @@ describe('useAJVForm should properly set errors programmatically using setErrors
586
586
expect ( result . current . state . description . error ) . toBe ( 'Monkey message' ) ;
587
587
} ) ;
588
588
589
+ it ( 'sets the errors using form.setErrors without affecting other state' , ( ) => {
590
+ const initialData = { title : 'Foo' , description : 'Bar' } ;
591
+ const schema : JSONSchemaType < { title : string ; description : string } > = {
592
+ type : 'object' ,
593
+ required : [ 'title' , 'description' ] ,
594
+ properties : {
595
+ title : { type : 'string' } ,
596
+ description : { type : 'string' } ,
597
+ } ,
598
+ } ;
599
+
600
+ const { result } = renderHook ( ( ) => useAJVForm ( initialData , schema ) ) ;
601
+
602
+ result . current . setErrors ( [
603
+ {
604
+ instancePath : '/description' ,
605
+ keyword : 'required' ,
606
+ params : { missingProperty : 'description' } ,
607
+ schemaPath : '#/required' ,
608
+ } ,
609
+ ] ) ;
610
+
611
+ expect ( result . current . state . title . value ) . toBe ( 'Foo' ) ;
612
+ expect ( result . current . state . description . value ) . toBe ( 'Bar' ) ;
613
+
614
+ expect ( result . current . state . description . error ) . toBe ( 'Monkey message' ) ;
615
+ } ) ;
616
+
589
617
it ( 'should handle conditional validations on locationType correctly' , ( ) => {
590
618
/**
591
619
* Test Scenario:
You can’t perform that action at this time.
0 commit comments