@@ -194,6 +194,83 @@ describe('argsForFetch', () => {
194194} ,
195195] )
196196} )
197+
198+ it ( 'returns fetch args and converts FormData into url search params on GET or HEAD' , ( ) => {
199+ const getState = ( ) => {
200+ return {
201+ superglue :{ } ,
202+ }
203+ }
204+
205+ const formData = new FormData ( )
206+ formData . append ( 'title' , 'hello' )
207+
208+ const args = argsForFetch ( getState , '/foo' , { body :formData } )
209+
210+ expect ( args ) . toEqual ( [
211+ 'https://example.com/foo?format=json&title=hello' ,
212+ {
213+ method :'GET' ,
214+ headers :{
215+ accept :'application/json' ,
216+ 'x-requested-with' :'XMLHttpRequest' ,
217+ 'x-superglue-request' :'true' ,
218+ } ,
219+ signal :undefined ,
220+ credentials :'same-origin' ,
221+ } ,
222+ ] )
223+
224+ const args2 = argsForFetch ( getState , '/foo' , {
225+ method :'HEAD' ,
226+ body :formData ,
227+ } )
228+
229+ expect ( args2 ) . toEqual ( [
230+ 'https://example.com/foo?format=json&title=hello' ,
231+ {
232+ method :'HEAD' ,
233+ headers :{
234+ accept :'application/json' ,
235+ 'x-requested-with' :'XMLHttpRequest' ,
236+ 'x-superglue-request' :'true' ,
237+ } ,
238+ signal :undefined ,
239+ credentials :'same-origin' ,
240+ } ,
241+ ] )
242+ } )
243+
244+ it ( 'returns fetch args and merges FormData into the existing url search params' , ( ) => {
245+ const getState = ( ) => {
246+ return {
247+ superglue :{ } ,
248+ }
249+ }
250+
251+ const formData = new FormData ( )
252+ formData . append ( 'title' , 'hello' )
253+ formData . append ( 'option' , '1' )
254+ formData . append ( 'option' , '2' )
255+
256+ const args = argsForFetch ( getState , '/foo?title=news&name=jim&option=100' , {
257+ body :formData ,
258+ } )
259+
260+ expect ( args ) . toEqual ( [
261+ 'https://example.com/foo?name=jim&format=json&title=hello&option=1&option=2' ,
262+ {
263+ method :'GET' ,
264+ headers :{
265+ accept :'application/json' ,
266+ 'x-requested-with' :'XMLHttpRequest' ,
267+ 'x-superglue-request' :'true' ,
268+ } ,
269+ signal :undefined ,
270+ credentials :'same-origin' ,
271+ } ,
272+ ] )
273+ } )
197274} )
198275
199276describe ( 'handleServerErrors' , ( ) => {