@@ -31,7 +31,7 @@ test('createServerFn without middleware', () => {
3131 } )
3232} )
3333
34- test ( 'createServerFn with validator' , ( ) => {
34+ test ( 'createServerFn with validator function ' , ( ) => {
3535 const fnAfterValidator = createServerFn ( {
3636 method : 'GET' ,
3737 } ) . inputValidator ( ( input : { input : string } ) => ( {
@@ -62,6 +62,91 @@ test('createServerFn with validator', () => {
6262 expectTypeOf < ReturnType < typeof fn > > ( ) . resolves . toEqualTypeOf < void > ( )
6363} )
6464
65+ test ( 'createServerFn with async validator function' , ( ) => {
66+ const fnAfterValidator = createServerFn ( {
67+ method : 'GET' ,
68+ } ) . inputValidator ( ( input : string ) => Promise . resolve ( input ) )
69+
70+ expectTypeOf ( fnAfterValidator ) . toHaveProperty ( 'handler' )
71+ expectTypeOf ( fnAfterValidator ) . toHaveProperty ( 'middleware' )
72+ expectTypeOf ( fnAfterValidator ) . not . toHaveProperty ( 'inputValidator' )
73+
74+ const fn = fnAfterValidator . handler ( ( options ) => {
75+ expectTypeOf ( options ) . toEqualTypeOf < {
76+ method : 'GET'
77+ context : undefined
78+ data : string
79+ signal : AbortSignal
80+ } > ( )
81+ } )
82+
83+ expectTypeOf ( fn ) . parameter ( 0 ) . toEqualTypeOf < {
84+ data : string
85+ headers ?: HeadersInit
86+ signal ?: AbortSignal
87+ } > ( )
88+
89+ expectTypeOf < ReturnType < typeof fn > > ( ) . resolves . toEqualTypeOf < void > ( )
90+ } )
91+
92+ test ( 'createServerFn with validator with parse method' , ( ) => {
93+ const fnAfterValidator = createServerFn ( {
94+ method : 'GET' ,
95+ } ) . inputValidator ( {
96+ parse : ( input : string ) => input ,
97+ } )
98+
99+ expectTypeOf ( fnAfterValidator ) . toHaveProperty ( 'handler' )
100+ expectTypeOf ( fnAfterValidator ) . toHaveProperty ( 'middleware' )
101+ expectTypeOf ( fnAfterValidator ) . not . toHaveProperty ( 'inputValidator' )
102+
103+ const fn = fnAfterValidator . handler ( ( options ) => {
104+ expectTypeOf ( options ) . toEqualTypeOf < {
105+ method : 'GET'
106+ context : undefined
107+ data : string
108+ signal : AbortSignal
109+ } > ( )
110+ } )
111+
112+ expectTypeOf ( fn ) . parameter ( 0 ) . toEqualTypeOf < {
113+ data : string
114+ headers ?: HeadersInit
115+ signal ?: AbortSignal
116+ } > ( )
117+
118+ expectTypeOf < ReturnType < typeof fn > > ( ) . resolves . toEqualTypeOf < void > ( )
119+ } )
120+
121+ test ( 'createServerFn with async validator with parse method' , ( ) => {
122+ const fnAfterValidator = createServerFn ( {
123+ method : 'GET' ,
124+ } ) . inputValidator ( {
125+ parse : ( input : string ) => Promise . resolve ( input ) ,
126+ } )
127+
128+ expectTypeOf ( fnAfterValidator ) . toHaveProperty ( 'handler' )
129+ expectTypeOf ( fnAfterValidator ) . toHaveProperty ( 'middleware' )
130+ expectTypeOf ( fnAfterValidator ) . not . toHaveProperty ( 'inputValidator' )
131+
132+ const fn = fnAfterValidator . handler ( ( options ) => {
133+ expectTypeOf ( options ) . toEqualTypeOf < {
134+ method : 'GET'
135+ context : undefined
136+ data : string
137+ signal : AbortSignal
138+ } > ( )
139+ } )
140+
141+ expectTypeOf ( fn ) . parameter ( 0 ) . toEqualTypeOf < {
142+ data : string
143+ headers ?: HeadersInit
144+ signal ?: AbortSignal
145+ } > ( )
146+
147+ expectTypeOf < ReturnType < typeof fn > > ( ) . resolves . toEqualTypeOf < void > ( )
148+ } )
149+
65150test ( 'createServerFn with standard validator' , ( ) => {
66151 interface SyncValidator {
67152 readonly '~standard' : {
0 commit comments