File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,17 @@ function isFile (value) {
29
29
typeof value . name === 'string'
30
30
}
31
31
32
+ function isFormData ( value ) {
33
+ return value instanceof FormData
34
+ }
35
+
32
36
function objectToFormData ( obj , cfg , fd , pre ) {
37
+ if ( isFormData ( cfg ) ) {
38
+ pre = fd
39
+ fd = cfg
40
+ cfg = null
41
+ }
42
+
33
43
cfg = cfg || { }
34
44
cfg . indices = cfg . indices || false
35
45
fd = fd || new FormData ( )
Original file line number Diff line number Diff line change @@ -338,3 +338,19 @@ test('File', t => {
338
338
] )
339
339
t . is ( formData . get ( 'foo' ) , foo )
340
340
} )
341
+
342
+ test ( 'FormData instance as second parameter' , t => {
343
+ const foo = 'foo'
344
+ const data = new FormData ( )
345
+ const formData = objectToFormData ( {
346
+ foo
347
+ } , data )
348
+
349
+ t . true ( formData . append . calledOnce )
350
+ t . deepEqual ( formData . append . getCall ( 0 ) . args , [
351
+ 'foo' ,
352
+ foo
353
+ ] )
354
+ t . is ( formData . get ( 'foo' ) , foo )
355
+ t . is ( data , formData )
356
+ } )
You can’t perform that action at this time.
0 commit comments