@@ -272,7 +272,7 @@ describe('Request', () => {
272
272
} ) ;
273
273
} ) ;
274
274
275
- it ( 'should read formData after clone with FormData body' , async ( ) => {
275
+ it ( 'should read formData after clone with web FormData body' , async ( ) => {
276
276
const ogFormData = new WebFormData ( ) ;
277
277
ogFormData . append ( 'a' , 1 ) ;
278
278
ogFormData . append ( 'b' , 2 ) ;
@@ -284,11 +284,45 @@ describe('Request', () => {
284
284
} ) ;
285
285
const clonedRequest = request . clone ( ) ;
286
286
287
- return clonedRequest . formData ( ) . then ( clonedFormData => {
287
+ return clonedRequest . formData ( ) . then ( async clonedFormData => {
288
288
expect ( clonedFormData . get ( 'a' ) ) . to . equal ( "1" ) ;
289
289
expect ( clonedFormData . get ( 'b' ) ) . to . equal ( "2" ) ;
290
290
const file = clonedFormData . get ( 'file' )
291
- expect ( typeof file ) . to . equal ( "object" ) ;
291
+ if ( typeof file !== "object" ) {
292
+ throw new Error ( "File is not an object" ) ;
293
+ }
294
+ expect ( file . name ) . to . equal ( "file.txt" ) ;
295
+ expect ( file . type ) . to . equal ( "application/octet-stream" ) ;
296
+ expect ( file . size ) . to . equal ( 7 ) ;
297
+ expect ( await file . text ( ) ) . to . equal ( "content" ) ;
298
+ expect ( file . lastModified ) . to . be . a ( 'number' ) ;
299
+ } ) ;
300
+ } ) ;
301
+
302
+ it ( 'should read formData after clone with node FormData body' , async ( ) => {
303
+ const ogFormData = new FormData ( ) ;
304
+ ogFormData . append ( 'a' , '1' ) ;
305
+ ogFormData . append ( 'b' , '2' ) ;
306
+ ogFormData . append ( 'file' , Buffer . from ( 'content' ) , { filename : "file.txt" } ) ;
307
+
308
+ const request = new Request ( base , {
309
+ method : 'POST' ,
310
+ body : ogFormData ,
311
+ } ) ;
312
+ const clonedRequest = request . clone ( ) ;
313
+
314
+ return clonedRequest . formData ( ) . then ( async clonedFormData => {
315
+ expect ( clonedFormData . get ( 'a' ) ) . to . equal ( "1" ) ;
316
+ expect ( clonedFormData . get ( 'b' ) ) . to . equal ( "2" ) ;
317
+ const file = clonedFormData . get ( 'file' )
318
+ if ( typeof file !== "object" ) {
319
+ throw new Error ( "File is not an object" ) ;
320
+ }
321
+ expect ( file . name ) . to . equal ( "file.txt" ) ;
322
+ expect ( file . type ) . to . equal ( "text/plain" ) ;
323
+ expect ( file . size ) . to . equal ( 7 ) ;
324
+ expect ( await file . text ( ) ) . to . equal ( "content" ) ;
325
+ expect ( file . lastModified ) . to . be . a ( 'number' ) ;
292
326
} ) ;
293
327
} ) ;
294
328
} ) ;
0 commit comments