File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -226,4 +226,12 @@ describe('Validator', () => {
226226
227227 expect ( validator . first ( [ 'name[0].kh' ] ) ) . toEqual ( 'This fist name field is required' )
228228 } )
229+
230+ it ( 'should reflect the field name by camel or snake case' , ( ) => {
231+ const errors = { firstName : [ 'This fist name field is required' ] }
232+ validator . fill ( errors )
233+
234+ expect ( validator . has ( [ 'first_name' ] ) ) . toBeTruthy ( )
235+ expect ( validator . first ( [ 'first_name' ] ) ) . toEqual ( 'This fist name field is required' )
236+ } )
229237} )
Original file line number Diff line number Diff line change @@ -31,8 +31,8 @@ class Validator {
3131 }
3232
3333 first ( field : string | string [ ] ) : string | Record < string , any > | undefined {
34- const fields = this . fields ( field )
3534 if ( Array . isArray ( field ) ) {
35+ const fields = this . fields ( field )
3636 for ( const f of fields ) {
3737 if ( ! has ( this . errors , f ) ) continue
3838 return this . first ( f )
@@ -117,7 +117,7 @@ class Validator {
117117 this . clear ( names )
118118 }
119119
120- fields ( field : string | string [ ] ) {
120+ fields ( field : string | string [ ] ) : string [ ] {
121121 const fields = [ ]
122122 if ( Array . isArray ( field ) ) {
123123 for ( const f of field ) {
You can’t perform that action at this time.
0 commit comments