2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-17 19:21:29 +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
+12
View File
@@ -33,6 +33,18 @@ describe('defaults', function () {
expect(defaults.transformRequest[0](null, headers)).toEqual('null');
});
it("should transform the plain data object to a FormData instance 'Content-Type' if header is 'multipart/form-data'", function() {
var headers = {
'Content-Type': 'multipart/form-data'
};
var payload = {x: 1};
var transformed = defaults.transformRequest[0](payload, headers);
expect(transformed).toEqual(jasmine.any(FormData));
});
it('should do nothing to request string', function () {
expect(defaults.transformRequest[0]('foo=bar')).toEqual('foo=bar');
});
+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]);
});
});
+3 -1
View File
@@ -24,7 +24,9 @@ describe('instance', function () {
'getUri',
'isAxiosError',
'VERSION',
'default'].indexOf(prop) > -1) {
'default',
'toFormData'
].indexOf(prop) > -1) {
continue;
}
expect(typeof instance[prop]).toBe(typeof axios[prop]);
+10
View File
@@ -0,0 +1,10 @@
var kindOf = require('../../../lib/utils').kindOf;
describe('utils::kindOf', function () {
it('should return object tag', function () {
expect(kindOf({})).toEqual('object');
// cached result
expect(kindOf({})).toEqual('object');
expect(kindOf([])).toEqual('array');
});
});
+5
View File
@@ -77,4 +77,9 @@ describe('utils::isX', function () {
expect(utils.isURLSearchParams(new URLSearchParams())).toEqual(true);
expect(utils.isURLSearchParams('foo=1&bar=2')).toEqual(false);
});
it('should validate TypedArray instance', function () {
expect(utils.isTypedArray(new Uint8Array([1, 2, 3]))).toEqual(true);
expect(utils.isTypedArray([1, 2, 3])).toEqual(false);
});
});
+10
View File
@@ -0,0 +1,10 @@
var kindOfTest = require('../../../lib/utils').kindOfTest;
describe('utils::endsWith', function () {
it('should return true if the string ends with passed substring', function () {
var test = kindOfTest('number');
expect(test(123)).toEqual(true);
expect(test('123')).toEqual(false);
});
});
+10
View File
@@ -0,0 +1,10 @@
var kindOf = require('../../../lib/utils').kindOf;
describe('utils::kindOf', function () {
it('should return object tag', function () {
expect(kindOf({})).toEqual('object');
// cached result
expect(kindOf({})).toEqual('object');
expect(kindOf([])).toEqual('array');
});
});
+10
View File
@@ -0,0 +1,10 @@
var toArray = require('../../../lib/utils').toArray;
describe('utils::kindOf', function () {
it('should return object tag', function () {
expect(toArray()).toEqual(null);
expect(toArray([])).toEqual([]);
expect(toArray([1])).toEqual([1]);
expect(toArray([1, 2, 3])).toEqual([1, 2, 3]);
});
});