@@ -148,6 +148,15 @@ export const router = c.router(
148148 } ,
149149 contentType : 'multipart/form-data' ,
150150 } ,
151+ uploadArray : {
152+ method : 'POST' ,
153+ path : '/upload-array' ,
154+ body : c . type < { files : File [ ] } > ( ) ,
155+ responses : {
156+ 200 : c . type < { message : string } > ( ) ,
157+ } ,
158+ contentType : 'multipart/form-data' ,
159+ } ,
151160 } ,
152161 {
153162 baseHeaders : z . object ( {
@@ -628,6 +637,38 @@ describe('client', () => {
628637 } ,
629638 } ) ;
630639 } ) ;
640+
641+ it ( 'w/ File Array' , async ( ) => {
642+ const value = { key : 'value' } ;
643+ fetchMock . postOnce (
644+ {
645+ url : 'https://api.com/upload-array' ,
646+ } ,
647+ { body : value , status : 200 } ,
648+ ) ;
649+
650+ const files = [
651+ new File ( [ '' ] , 'filename-1' , { type : 'text/plain' } ) ,
652+ new File ( [ '' ] , 'filename-2' , { type : 'text/plain' } ) ,
653+ ] ;
654+
655+ const result = await client . uploadArray ( {
656+ body : { files } ,
657+ } ) ;
658+
659+ expect ( result . body ) . toStrictEqual ( value ) ;
660+ expect ( result . status ) . toBe ( 200 ) ;
661+ expect ( result . headers . get ( 'Content-Length' ) ) . toBe ( '15' ) ;
662+ expect ( result . headers . get ( 'Content-Type' ) ) . toBe ( 'application/json' ) ;
663+
664+ expect ( fetchMock ) . toHaveLastFetched ( true , {
665+ matcher : ( _ , options ) => {
666+ const formData = options . body as FormData ;
667+ const formDataFiles = formData . getAll ( 'files' ) ;
668+ return formDataFiles [ 0 ] === files [ 0 ] && formDataFiles [ 1 ] === files [ 1 ] ;
669+ } ,
670+ } ) ;
671+ } ) ;
631672 } ) ;
632673
633674 describe ( 'application/x-www-form-urlencoded' , ( ) => {
0 commit comments