@@ -126,6 +126,34 @@ describe("Multipart", function () {
126126 } ) ;
127127 } ) ;
128128
129+ describe ( "#formData" , function ( ) {
130+ it ( "should correctly return the FormData of the Multipart" , async function ( ) {
131+ const formData = new FormData ( ) ;
132+ formData . append ( "foo" , "bar" ) ;
133+ formData . append ( "bar" , "baz" ) ;
134+ formData . append ( "file" , new Blob ( [ "console.log('hello world');" ] , { type : "application/javascript" } ) , "hello.js" ) ;
135+
136+ const multipart = await Multipart . formData ( formData ) ;
137+ const parsedFormData = multipart . formData ( ) ;
138+
139+ expect ( parsedFormData ) . to . be . an . instanceof ( FormData ) ;
140+ expect ( parsedFormData . get ( "foo" ) ) . to . equal ( "bar" ) ;
141+ expect ( parsedFormData . get ( "bar" ) ) . to . equal ( "baz" ) ;
142+ const file = parsedFormData . get ( "file" ) ;
143+ expect ( file ) . to . be . an . instanceof ( File ) ;
144+ expect ( file . name ) . to . equal ( "hello.js" ) ;
145+ expect ( file . type ) . to . equal ( "application/javascript" ) ;
146+ expect ( new TextDecoder ( ) . decode ( await file . arrayBuffer ( ) ) ) . to . equal ( "console.log('hello world');" ) ;
147+ } ) ;
148+
149+ it ( "should handle empty FormData multipart" , async function ( ) {
150+ const multipart = await Multipart . formData ( new FormData ( ) ) ;
151+ const formData = multipart . formData ( ) ;
152+ expect ( formData ) . to . be . an . instanceof ( FormData ) ;
153+ expect ( Object . keys ( Object . fromEntries ( formData . entries ( ) ) ) . length ) . to . equal ( 0 ) ;
154+ } ) ;
155+ } ) ;
156+
129157 describe ( "#body" , function ( ) {
130158 it ( "should correctly return the body of the Multipart" , function ( ) {
131159 const boundary = "test-boundary" ;
0 commit comments