mirror of
https://github.com/tenrok/axios.git
synced 2026-05-15 11:59:42 +03:00
c008e57fe4
* Draft * Added `formDataToJSON` helper; Added `axios.formToJSON` method; Added client tests; Co-authored-by: Jay <jasonsaayman@gmail.com>
51 lines
1.1 KiB
JavaScript
51 lines
1.1 KiB
JavaScript
var formDataToJSON = require('../../../lib/helpers/formDataToJSON');
|
|
|
|
describe('formDataToJSON', function () {
|
|
it('should convert a FormData Object to JSON Object', function () {
|
|
const formData = new FormData();
|
|
|
|
formData.append('foo[bar][baz]', '123');
|
|
|
|
expect(formDataToJSON(formData)).toEqual({
|
|
foo: {
|
|
bar: {
|
|
baz: '123'
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
it('should convert repeatable values as an array', function () {
|
|
const formData = new FormData();
|
|
|
|
formData.append('foo', '1');
|
|
formData.append('foo', '2');
|
|
|
|
expect(formDataToJSON(formData)).toEqual({
|
|
foo: ['1', '2']
|
|
});
|
|
});
|
|
|
|
it('should convert props with empty brackets to arrays', function () {
|
|
const formData = new FormData();
|
|
|
|
formData.append('foo[]', '1');
|
|
formData.append('foo[]', '2');
|
|
|
|
expect(formDataToJSON(formData)).toEqual({
|
|
foo: ['1', '2']
|
|
});
|
|
});
|
|
|
|
it('should supported indexed arrays', function () {
|
|
const formData = new FormData();
|
|
|
|
formData.append('foo[0]', '1');
|
|
formData.append('foo[1]', '2');
|
|
|
|
expect(formDataToJSON(formData)).toEqual({
|
|
foo: ['1', '2']
|
|
});
|
|
});
|
|
});
|