mirror of
https://github.com/tenrok/axios.git
synced 2026-06-17 19:21:29 +03:00
Fixing failing tests
This commit is contained in:
@@ -6,6 +6,7 @@ var spread = require('./spread');
|
|||||||
var axios = module.exports = function axios(config) {
|
var axios = module.exports = function axios(config) {
|
||||||
config = utils.merge({
|
config = utils.merge({
|
||||||
method: 'get',
|
method: 'get',
|
||||||
|
headers: {},
|
||||||
transformRequest: defaults.transformRequest,
|
transformRequest: defaults.transformRequest,
|
||||||
transformResponse: defaults.transformResponse
|
transformResponse: defaults.transformResponse
|
||||||
}, config);
|
}, config);
|
||||||
|
|||||||
+1
-1
@@ -19,7 +19,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
if (utils.isObject(data) && !utils.isFile(data) && !utils.isBlob(data)) {
|
if (utils.isObject(data) && !utils.isFile(data) && !utils.isBlob(data)) {
|
||||||
// Set application/json if no Content-Type has been specified
|
// Set application/json if no Content-Type has been specified
|
||||||
if (utils.isUndefined(headers['Content-Type'])) {
|
if (!utils.isUndefined(headers) && utils.isUndefined(headers['Content-Type'])) {
|
||||||
headers['Content-Type'] = 'application/json;charset=utf-8';
|
headers['Content-Type'] = 'application/json;charset=utf-8';
|
||||||
}
|
}
|
||||||
return JSON.stringify(data);
|
return JSON.stringify(data);
|
||||||
|
|||||||
@@ -56,6 +56,16 @@ function isNumber(val) {
|
|||||||
return typeof val === 'number';
|
return typeof val === 'number';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a value is undefined
|
||||||
|
*
|
||||||
|
* @param {Object} val The value to test
|
||||||
|
* @returns {boolean} True if the value is undefined, otherwise false
|
||||||
|
*/
|
||||||
|
function isUndefined(val) {
|
||||||
|
return typeof val === 'undefined';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if a value is an Object
|
* Determine if a value is an Object
|
||||||
*
|
*
|
||||||
@@ -182,6 +192,7 @@ module.exports = {
|
|||||||
isString: isString,
|
isString: isString,
|
||||||
isNumber: isNumber,
|
isNumber: isNumber,
|
||||||
isObject: isObject,
|
isObject: isObject,
|
||||||
|
isUndefined: isUndefined,
|
||||||
isDate: isDate,
|
isDate: isDate,
|
||||||
isFile: isFile,
|
isFile: isFile,
|
||||||
isBlob: isBlob,
|
isBlob: isBlob,
|
||||||
|
|||||||
@@ -30,10 +30,7 @@ describe('wrapper', function () {
|
|||||||
axios({
|
axios({
|
||||||
method: 'post',
|
method: 'post',
|
||||||
url: '/foo',
|
url: '/foo',
|
||||||
data: {
|
data: 'fizz=buzz'
|
||||||
firstName: 'foo',
|
|
||||||
lastName: 'bar'
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var request = jasmine.Ajax.requests.mostRecent();
|
var request = jasmine.Ajax.requests.mostRecent();
|
||||||
@@ -45,6 +42,20 @@ describe('wrapper', function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should use application/json when posting an object', function () {
|
||||||
|
axios({
|
||||||
|
url: '/foo/bar',
|
||||||
|
method: 'post',
|
||||||
|
data: {
|
||||||
|
firstName: 'foo',
|
||||||
|
lastName: 'bar'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var request = jasmine.Ajax.requests.mostRecent();
|
||||||
|
expect(request.requestHeaders['Content-Type']).toEqual('application/json;charset=utf-8');
|
||||||
|
});
|
||||||
|
|
||||||
it('should support binary data as array buffer', function () {
|
it('should support binary data as array buffer', function () {
|
||||||
var input = new Int8Array(2);
|
var input = new Int8Array(2);
|
||||||
input[0] = 1;
|
input[0] = 1;
|
||||||
|
|||||||
@@ -19,6 +19,12 @@ module.exports = {
|
|||||||
test.done();
|
test.done();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
testIsUndefined: function (test) {
|
||||||
|
test.equals(utils.isUndefined(), true);
|
||||||
|
test.equals(utils.isUndefined(null), false);
|
||||||
|
test.done();
|
||||||
|
},
|
||||||
|
|
||||||
testIsObject: function (test) {
|
testIsObject: function (test) {
|
||||||
test.equals(utils.isObject({}), true);
|
test.equals(utils.isObject({}), true);
|
||||||
test.equals(utils.isObject(null), false);
|
test.equals(utils.isObject(null), false);
|
||||||
|
|||||||
Reference in New Issue
Block a user