Skip to content

Commit 9a178f7

Browse files
Merge pull request #1 from citizensadvice/allow-form-data-object
Allow form data object
2 parents 2870c3f + 7419922 commit 9a178f7

File tree

5 files changed

+1972
-1639
lines changed

5 files changed

+1972
-1639
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# CHANGELOG
2+
3+
## v1.1.0 _8 August 2022_
4+
5+
- Allows passing an existing `FormData` object

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function normalizeParams(params, name, v, depth) {
9191
}
9292

9393
export default function formToRackParams(form) {
94-
const data = new FormData(form);
94+
const data = form instanceof FormData ? form : new FormData(form);
9595
const serialized = Object.create(null);
9696

9797
for (const [key, value] of data) {

index.test.js

+10
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,13 @@ describe('x[y]=1&x[y][][w]=2', () => {
138138
}).toThrow('expected Array (got string) for param `y`');
139139
});
140140
});
141+
142+
describe('with a formData object', () => {
143+
it('is converted to params', () => {
144+
makeDOM('x=1');
145+
const formData = new FormData(document.querySelector('form'));
146+
expect(serializeForm(formData)).toEqual({
147+
x: '1',
148+
});
149+
});
150+
});

0 commit comments

Comments
 (0)