File tree 2 files changed +27
-2
lines changed
2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -189,4 +189,29 @@ describe('yupResolver', () => {
189
189
expect ( schemaSyncSpy ) . not . toHaveBeenCalled ( ) ;
190
190
expect ( result ) . toEqual ( { errors : { } , values : validData } ) ;
191
191
} ) ;
192
+
193
+ it ( 'shoud validate a lazy schema with success' , async ( ) => {
194
+ const lazySchema = yup . lazy ( ( ) => yup . object ( ) . shape ( { firstName : yup . string ( ) . optional ( ) } ) ) ;
195
+
196
+ const schemaSpy = vi . spyOn ( lazySchema , 'validate' ) ;
197
+ const schemaSyncSpy = vi . spyOn ( lazySchema , 'validateSync' ) ;
198
+
199
+ const result = await yupResolver ( lazySchema , undefined , ) (
200
+ { firstName : "resolver" } ,
201
+ undefined ,
202
+ {
203
+ fields : {
204
+ firstName : {
205
+ ref : { name : 'firstName' } ,
206
+ name : 'firstName' ,
207
+ }
208
+ } ,
209
+ shouldUseNativeValidation,
210
+ } ,
211
+ ) ;
212
+
213
+ expect ( schemaSpy ) . toHaveBeenCalledTimes ( 1 ) ;
214
+ expect ( schemaSyncSpy ) . not . toHaveBeenCalled ( ) ;
215
+ expect ( result ) . toEqual ( { errors : { } , values : { firstName : "resolver" } } ) ;
216
+ } ) ;
192
217
} ) ;
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ const parseErrorSchema = (
43
43
} ;
44
44
45
45
export function yupResolver < TFieldValues extends FieldValues > (
46
- schema : Yup . ObjectSchema < TFieldValues > ,
46
+ schema : Yup . ObjectSchema < TFieldValues > | ReturnType < typeof Yup . lazy > ,
47
47
schemaOptions : Parameters < ( typeof schema ) [ 'validate' ] > [ 1 ] = { } ,
48
48
resolverOptions : {
49
49
/**
@@ -90,7 +90,7 @@ export function yupResolver<TFieldValues extends FieldValues>(
90
90
parseErrorSchema (
91
91
e ,
92
92
! options . shouldUseNativeValidation &&
93
- options . criteriaMode === 'all' ,
93
+ options . criteriaMode === 'all' ,
94
94
) ,
95
95
options ,
96
96
) ,
You can’t perform that action at this time.
0 commit comments