@@ -204,3 +204,54 @@ test('transforms flat object to nested object with root error for field array',
204
204
] ,
205
205
} ) ;
206
206
} ) ;
207
+
208
+ test ( 'ensures consistent ordering when a field array has a root error and an error in the non-first element' , ( ) => {
209
+ const result = toNestErrors (
210
+ {
211
+ 'fieldArrayWithRootError.1.name' : {
212
+ type : 'second' ,
213
+ message : 'second message' ,
214
+ } ,
215
+ fieldArrayWithRootError : { type : 'root-error' , message : 'root message' } ,
216
+ } ,
217
+ {
218
+ fields : {
219
+ fieldArrayWithRootError : {
220
+ name : 'fieldArrayWithRootError' ,
221
+ ref : { name : 'fieldArrayWithRootError' } ,
222
+ } ,
223
+ 'fieldArrayWithRootError.0.name' : {
224
+ name : 'fieldArrayWithRootError.0.name' ,
225
+ ref : { name : 'fieldArrayWithRootError.0.name' } ,
226
+ } ,
227
+ 'fieldArrayWithRootError.1.name' : {
228
+ name : 'fieldArrayWithRootError.1.name' ,
229
+ ref : { name : 'fieldArrayWithRootError.1.name' } ,
230
+ } ,
231
+ } ,
232
+ names : [
233
+ 'fieldArrayWithRootError' ,
234
+ 'fieldArrayWithRootError.0.name' ,
235
+ 'fieldArrayWithRootError.1.name' ,
236
+ ] ,
237
+ shouldUseNativeValidation : false ,
238
+ } ,
239
+ ) ;
240
+
241
+ expect ( result ) . toEqual ( {
242
+ fieldArrayWithRootError : {
243
+ '1' : {
244
+ name : {
245
+ type : 'second' ,
246
+ message : 'second message' ,
247
+ ref : { name : 'fieldArrayWithRootError.1.name' } ,
248
+ } ,
249
+ } ,
250
+ root : {
251
+ type : 'root-error' ,
252
+ message : 'root message' ,
253
+ ref : { name : 'fieldArrayWithRootError' } ,
254
+ } ,
255
+ } ,
256
+ } ) ;
257
+ } ) ;
0 commit comments