Commit 985c48d 1 parent 077486a commit 985c48d Copy full SHA for 985c48d
File tree 2 files changed +30
-1
lines changed
2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,35 @@ test('transforms flat object to nested object and shouldUseNativeValidation: tru
39
39
) . toHaveBeenCalledWith ( flatObject . name . message ) ;
40
40
} ) ;
41
41
42
+ test ( 'transforms flat object to nested object with names option' , ( ) => {
43
+ const result = toNestErrors (
44
+ {
45
+ username : {
46
+ type : 'custom' ,
47
+ message : 'error' ,
48
+ } ,
49
+ } ,
50
+ {
51
+ names : [ 'username' , 'username.first' ] ,
52
+ fields : {
53
+ username : {
54
+ name : 'username' ,
55
+ ref : { name : 'username' } ,
56
+ } ,
57
+ } ,
58
+ shouldUseNativeValidation : false ,
59
+ } ,
60
+ ) ;
61
+
62
+ expect ( result ) . toEqual ( {
63
+ username : {
64
+ type : 'custom' ,
65
+ message : 'error' ,
66
+ ref : { name : 'username' } ,
67
+ } ,
68
+ } ) ;
69
+ } ) ;
70
+
42
71
test ( 'transforms flat object to nested object with root error for field array' , ( ) => {
43
72
const result = toNestErrors (
44
73
{
Original file line number Diff line number Diff line change @@ -38,4 +38,4 @@ export const toNestErrors = <TFieldValues extends FieldValues>(
38
38
const isNameInFieldArray = (
39
39
names : InternalFieldName [ ] ,
40
40
name : InternalFieldName ,
41
- ) => names . some ( ( n ) => n . startsWith ( name + '.' ) ) ;
41
+ ) => names . some ( ( n ) => n . match ( `^ ${ name } \\.\\d+` ) ) ;
You can’t perform that action at this time.
0 commit comments