File tree Expand file tree Collapse file tree 3 files changed +26
-10
lines changed Expand file tree Collapse file tree 3 files changed +26
-10
lines changed Original file line number Diff line number Diff line change @@ -68,4 +68,17 @@ describe('vestResolver', () => {
68
68
) ,
69
69
) . toMatchSnapshot ( ) ;
70
70
} ) ;
71
+
72
+ it ( 'should call a suite with values, validated field names and a context as arguments' , async ( ) => {
73
+ const suite = vi . fn ( validationSuite ) as any as typeof validationSuite ;
74
+
75
+ await vestResolver ( suite ) ( validData , { some : 'context' } , {
76
+ fields : { username : fields . username } ,
77
+ names : [ 'username' ] ,
78
+ shouldUseNativeValidation,
79
+ } ) ;
80
+
81
+ expect ( suite ) . toHaveBeenCalledTimes ( 1 ) ;
82
+ expect ( suite ) . toHaveBeenCalledWith ( validData , [ 'username' ] , { some : 'context' } ) ;
83
+ } ) ;
71
84
} ) ;
Original file line number Diff line number Diff line change 1
1
import {
2
2
FieldValues ,
3
+ FieldName ,
3
4
ResolverOptions ,
4
5
ResolverResult ,
5
6
} from 'react-hook-form' ;
6
7
import * as Vest from 'vest' ;
7
8
8
- export type ICreateResult = ReturnType < typeof Vest . create > ;
9
+ export type ICreateResult < TValues extends FieldValues = FieldValues , TContext = any > = ReturnType <
10
+ typeof Vest . create < ( values : TValues , names ?: FieldName < TValues > [ ] , context ?: TContext ) => void >
11
+ > ;
9
12
10
- export type Resolver = (
11
- schema : ICreateResult ,
13
+ export type Resolver = < TValues extends FieldValues , TContext > (
14
+ schema : ICreateResult < TValues , TContext > ,
12
15
schemaOptions ?: never ,
13
16
factoryOptions ?: { mode ?: 'async' | 'sync' , rawValues ?: boolean ; } ,
14
- ) => < TFieldValues extends FieldValues , TContext > (
15
- values : TFieldValues ,
17
+ ) => (
18
+ values : TValues ,
16
19
context : TContext | undefined ,
17
- options : ResolverOptions < TFieldValues > ,
18
- ) => Promise < ResolverResult < TFieldValues > > ;
20
+ options : ResolverOptions < TValues > ,
21
+ ) => Promise < ResolverResult < TValues > > ;
19
22
20
23
export type VestErrors = Record < string , string [ ] > ;
Original file line number Diff line number Diff line change @@ -25,11 +25,11 @@ const parseErrorSchema = (
25
25
26
26
export const vestResolver : Resolver =
27
27
( schema , _ , resolverOptions = { } ) =>
28
- async ( values , _context , options ) => {
28
+ async ( values , context , options ) => {
29
29
const result =
30
30
resolverOptions . mode === 'sync'
31
- ? schema ( values )
32
- : await promisify ( schema ) ( values ) ;
31
+ ? schema ( values , options . names , context )
32
+ : await promisify ( schema ) ( values , options . names , context ) ;
33
33
34
34
if ( result . hasErrors ( ) ) {
35
35
return {
You can’t perform that action at this time.
0 commit comments