@@ -291,7 +291,7 @@ describe('Request', () => {
291291 } ) ;
292292 } ) ;
293293
294- it ( 'should read formData after clone with FormData body' , async ( ) => {
294+ it ( 'should read formData after clone with web FormData body' , async ( ) => {
295295 const ogFormData = new WebFormData ( ) ;
296296 ogFormData . append ( 'a' , 1 ) ;
297297 ogFormData . append ( 'b' , 2 ) ;
@@ -303,11 +303,45 @@ describe('Request', () => {
303303 } ) ;
304304 const clonedRequest = request . clone ( ) ;
305305
306- return clonedRequest . formData ( ) . then ( clonedFormData => {
306+ return clonedRequest . formData ( ) . then ( async clonedFormData => {
307307 expect ( clonedFormData . get ( 'a' ) ) . to . equal ( "1" ) ;
308308 expect ( clonedFormData . get ( 'b' ) ) . to . equal ( "2" ) ;
309309 const file = clonedFormData . get ( 'file' )
310- expect ( typeof file ) . to . equal ( "object" ) ;
310+ if ( typeof file !== "object" ) {
311+ throw new Error ( "File is not an object" ) ;
312+ }
313+ expect ( file . name ) . to . equal ( "file.txt" ) ;
314+ expect ( file . type ) . to . equal ( "application/octet-stream" ) ;
315+ expect ( file . size ) . to . equal ( 7 ) ;
316+ expect ( await file . text ( ) ) . to . equal ( "content" ) ;
317+ expect ( file . lastModified ) . to . be . a ( 'number' ) ;
318+ } ) ;
319+ } ) ;
320+
321+ it ( 'should read formData after clone with node FormData body' , async ( ) => {
322+ const ogFormData = new FormData ( ) ;
323+ ogFormData . append ( 'a' , '1' ) ;
324+ ogFormData . append ( 'b' , '2' ) ;
325+ ogFormData . append ( 'file' , Buffer . from ( 'content' ) , { filename : "file.txt" } ) ;
326+
327+ const request = new Request ( base , {
328+ method : 'POST' ,
329+ body : ogFormData ,
330+ } ) ;
331+ const clonedRequest = request . clone ( ) ;
332+
333+ return clonedRequest . formData ( ) . then ( async clonedFormData => {
334+ expect ( clonedFormData . get ( 'a' ) ) . to . equal ( "1" ) ;
335+ expect ( clonedFormData . get ( 'b' ) ) . to . equal ( "2" ) ;
336+ const file = clonedFormData . get ( 'file' )
337+ if ( typeof file !== "object" ) {
338+ throw new Error ( "File is not an object" ) ;
339+ }
340+ expect ( file . name ) . to . equal ( "file.txt" ) ;
341+ expect ( file . type ) . to . equal ( "text/plain" ) ;
342+ expect ( file . size ) . to . equal ( 7 ) ;
343+ expect ( await file . text ( ) ) . to . equal ( "content" ) ;
344+ expect ( file . lastModified ) . to . be . a ( 'number' ) ;
311345 } ) ;
312346 } ) ;
313347} ) ;
0 commit comments