Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7e62454

Browse files
committed
Add coverage to form data serialization
Form data should override anything in the URL params First we delete every key.Then append the new keys accounting for duplicate keys that representstructural arrays.
1 parent7698c14 commit7e62454

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

‎superglue/lib/utils/request.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ export function argsForFetch(
119119
options.bodyasunknownasRecord<string,string>
120120
)
121121

122-
// TODO: Add coverage for this
123122
// Form data should override anything in the URL params First we
124123
// delete every key. Then append the new keys accounting for
125124
// duplicate keys that represent structural arrays.

‎superglue/spec/lib/utils/request.spec.js‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
constgetState=()=>{
200+
return{
201+
superglue:{},
202+
}
203+
}
204+
205+
constformData=newFormData()
206+
formData.append('title','hello')
207+
208+
constargs=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+
constargs2=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+
constgetState=()=>{
246+
return{
247+
superglue:{},
248+
}
249+
}
250+
251+
constformData=newFormData()
252+
formData.append('title','hello')
253+
formData.append('option','1')
254+
formData.append('option','2')
255+
256+
constargs=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

199276
describe('handleServerErrors',()=>{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp