@@ -2909,11 +2909,8 @@ describe('form api', () => {
2909
2909
expect ( form . state . canSubmit ) . toBe ( true )
2910
2910
} )
2911
2911
2912
- it ( 'should pass the current values to the standard schema when calling parseValuesWithSchema' , async ( ) => {
2913
- const nameSchema = z . object ( {
2914
- name : z . string ( ) ,
2915
- } )
2916
- const firstNameSchema = z . object ( {
2912
+ it ( 'should pass the current values to the Standard Schema when calling parseValuesWithSchema' , async ( ) => {
2913
+ const schema = z . object ( {
2917
2914
firstName : z . string ( ) . min ( 3 ) ,
2918
2915
} )
2919
2916
@@ -2924,47 +2921,31 @@ describe('form api', () => {
2924
2921
} )
2925
2922
form . mount ( )
2926
2923
2927
- const nameSchemaResult = form . parseFieldValuesWithSchema ( nameSchema )
2928
- // Name schema should complain that 'name' is missing in our form
2929
- expect ( nameSchemaResult ) . not . toBeUndefined ( )
2930
- expect ( Array . isArray ( nameSchemaResult ) ) . not . toBe ( true )
2931
-
2932
- expect ( nameSchemaResult ) . toHaveProperty ( 'fields' )
2933
- expect ( nameSchemaResult ) . toHaveProperty ( 'form' )
2934
-
2935
- expect ( nameSchemaResult ?. fields ) . toHaveProperty ( 'name' )
2936
- expect ( Array . isArray ( nameSchemaResult ?. fields [ 'name' ] ) ) . toBe ( true )
2937
- expect ( nameSchemaResult ?. fields [ 'name' ] ) . not . toHaveLength ( 0 )
2938
-
2939
2924
// First name schema should complain that 'firstName' is too short
2940
- const firstNameSchemaResult =
2941
- form . parseFieldValuesWithSchema ( firstNameSchema )
2942
- expect ( firstNameSchemaResult ) . not . toBeUndefined ( )
2943
- expect ( Array . isArray ( firstNameSchemaResult ) ) . not . toBe ( true )
2925
+ const issueResult = form . parseFieldValuesWithSchema ( schema )
2926
+ expect ( issueResult ) . toBeDefined ( )
2927
+ expect ( Array . isArray ( issueResult ) ) . toBe ( false )
2944
2928
2945
- expect ( firstNameSchemaResult ) . toHaveProperty ( 'fields' )
2946
- expect ( firstNameSchemaResult ) . toHaveProperty ( 'form' )
2929
+ expect ( issueResult ) . toHaveProperty ( 'fields' )
2930
+ expect ( issueResult ) . toHaveProperty ( 'form' )
2947
2931
2948
- expect ( firstNameSchemaResult ?. fields ) . toHaveProperty ( 'firstName' )
2949
- expect ( Array . isArray ( firstNameSchemaResult ?. fields [ 'firstName' ] ) ) . toBe ( true )
2950
- expect ( firstNameSchemaResult ?. fields [ 'firstName' ] ) . not . toHaveLength ( 0 )
2932
+ expect ( issueResult ?. fields ) . toHaveProperty ( 'firstName' )
2933
+ expect ( Array . isArray ( issueResult ?. fields [ 'firstName' ] ) ) . toBe ( true )
2934
+ expect ( issueResult ?. fields [ 'firstName' ] ?. length ) . toBeGreaterThan ( 0 )
2951
2935
2952
2936
form . setFieldValue (
2953
2937
'firstName' ,
2954
2938
'some long name that satisfies firstNameSchemaResult' ,
2955
2939
)
2956
2940
// firstName should now be satisfied
2957
- const successResult = form . parseFieldValuesWithSchema ( firstNameSchema )
2941
+ const successResult = form . parseFieldValuesWithSchema ( schema )
2958
2942
expect ( successResult ) . toBeUndefined ( )
2959
2943
} )
2960
2944
2961
- it ( 'should pass the current values to the standard schema when calling parseValuesWithSchemaAsync' , async ( ) => {
2945
+ it ( 'should pass the current values to the Standard Schema when calling parseValuesWithSchemaAsync' , async ( ) => {
2962
2946
vi . useFakeTimers ( )
2963
2947
2964
- const nameSchema = z . object ( {
2965
- name : z . string ( ) ,
2966
- } )
2967
- const firstNameSchema = z . object ( {
2948
+ const schema = z . object ( {
2968
2949
firstName : z . string ( ) . min ( 3 ) ,
2969
2950
} )
2970
2951
@@ -2975,53 +2956,36 @@ describe('form api', () => {
2975
2956
} )
2976
2957
form . mount ( )
2977
2958
2978
- const nameSchemaPromise = form . parseFieldValuesWithSchemaAsync ( nameSchema )
2979
- expect ( nameSchemaPromise ) . toBeInstanceOf ( Promise )
2980
-
2981
- const nameSchemaResult = await nameSchemaPromise
2982
-
2983
- // Name schema should complain that 'name' is missing in our form
2984
- expect ( nameSchemaResult ) . not . toBeUndefined ( )
2985
- expect ( Array . isArray ( nameSchemaResult ) ) . not . toBe ( true )
2986
-
2987
- expect ( nameSchemaResult ) . toHaveProperty ( 'fields' )
2988
- expect ( nameSchemaResult ) . toHaveProperty ( 'form' )
2989
-
2990
- expect ( nameSchemaResult ?. fields ) . toHaveProperty ( 'name' )
2991
- expect ( Array . isArray ( nameSchemaResult ?. fields [ 'name' ] ) ) . toBe ( true )
2992
- expect ( nameSchemaResult ?. fields [ 'name' ] ) . not . toHaveLength ( 0 )
2993
-
2994
2959
// First name schema should complain that 'firstName' is too short
2995
- const firstNamePromise =
2996
- form . parseFieldValuesWithSchemaAsync ( firstNameSchema )
2997
- expect ( firstNamePromise ) . toBeInstanceOf ( Promise )
2960
+ const issuePromise = form . parseFieldValuesWithSchemaAsync ( schema )
2961
+ expect ( issuePromise ) . toBeInstanceOf ( Promise )
2998
2962
2999
- const firstNameSchemaResult = await firstNamePromise
2963
+ const issueResult = await issuePromise
3000
2964
3001
- expect ( firstNameSchemaResult ) . not . toBeUndefined ( )
3002
- expect ( Array . isArray ( firstNameSchemaResult ) ) . not . toBe ( true )
2965
+ expect ( issueResult ) . toBeDefined ( )
2966
+ expect ( Array . isArray ( issueResult ) ) . toBe ( false )
3003
2967
3004
- expect ( firstNameSchemaResult ) . toHaveProperty ( 'fields' )
3005
- expect ( firstNameSchemaResult ) . toHaveProperty ( 'form' )
2968
+ expect ( issueResult ) . toHaveProperty ( 'fields' )
2969
+ expect ( issueResult ) . toHaveProperty ( 'form' )
3006
2970
3007
- expect ( firstNameSchemaResult ?. fields ) . toHaveProperty ( 'firstName' )
3008
- expect ( Array . isArray ( firstNameSchemaResult ?. fields [ 'firstName' ] ) ) . toBe ( true )
3009
- expect ( firstNameSchemaResult ?. fields [ 'firstName' ] ) . not . toHaveLength ( 0 )
2971
+ expect ( issueResult ?. fields ) . toHaveProperty ( 'firstName' )
2972
+ expect ( Array . isArray ( issueResult ?. fields [ 'firstName' ] ) ) . toBe ( true )
2973
+ expect ( issueResult ?. fields [ 'firstName' ] ?. length ) . toBeGreaterThan ( 0 )
3010
2974
3011
2975
form . setFieldValue (
3012
2976
'firstName' ,
3013
2977
'some long name that satisfies firstNameSchemaResult' ,
3014
2978
)
3015
2979
3016
2980
// firstName should now be satisfied
3017
- const successPromise = form . parseFieldValuesWithSchemaAsync ( firstNameSchema )
2981
+ const successPromise = form . parseFieldValuesWithSchemaAsync ( schema )
3018
2982
expect ( successPromise ) . toBeInstanceOf ( Promise )
3019
2983
3020
2984
const successResult = await successPromise
3021
2985
expect ( successResult ) . toBeUndefined ( )
3022
2986
} )
3023
2987
3024
- it ( 'should throw an error when passing an async schema to parseValuesWithSchema' , async ( ) => {
2988
+ it ( 'should throw an error when passing an async Standard Schema to parseValuesWithSchema' , async ( ) => {
3025
2989
const testSchema = z
3026
2990
. object ( {
3027
2991
name : z . string ( ) ,
0 commit comments