2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-20 20:00:40 +03:00

Fixed merge conflicts

This commit is contained in:
Jay
2022-04-01 18:40:12 +02:00
22 changed files with 644 additions and 161 deletions
+35 -10
View File
@@ -1,18 +1,43 @@
var toFormData = require("../../../lib/helpers/toFormData");
var toFormData = require('../../../lib/helpers/toFormData');
describe("toFormData", function () {
it("Convert nested data object to FormDAta", function () {
describe('toFormData', function () {
it('should convert nested data object to FormData', function () {
var o = {
val: 123,
nested: {
arr: ["hello", "world"],
},
arr: ['hello', 'world']
}
};
convertedVal = toFormData(o);
expect(convertedVal instanceof FormData).toEqual(true);
expect(Array.from(convertedVal.keys()).length).toEqual(3);
expect(convertedVal.get("val")).toEqual("123")
expect(convertedVal.get("nested.arr.0")).toEqual("hello")
var form = toFormData(o);
expect(form instanceof FormData).toEqual(true);
expect(Array.from(form.keys()).length).toEqual(3);
expect(form.get('val')).toEqual('123');
expect(form.get('nested.arr.0')).toEqual('hello');
});
it('should append value whose key ends with [] as separate values with the same key', function () {
var data = {
'arr[]': [1, 2, 3]
};
var form = toFormData(data);
expect(Array.from(form.keys()).length).toEqual(3);
expect(form.getAll('arr[]')).toEqual(['1', '2', '3']);
});
it('should append value whose key ends with {} as a JSON string', function () {
var data = {
'obj{}': {x: 1, y: 2}
};
var str = JSON.stringify(data['obj{}']);
var form = toFormData(data);
expect(Array.from(form.keys()).length).toEqual(1);
expect(form.getAll('obj{}')).toEqual([str]);
});
});