mirror of
https://github.com/tenrok/axios.git
synced 2026-05-15 11:59:42 +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) {
|
||||
config = utils.merge({
|
||||
method: 'get',
|
||||
headers: {},
|
||||
transformRequest: defaults.transformRequest,
|
||||
transformResponse: defaults.transformResponse
|
||||
}, config);
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ module.exports = {
|
||||
}
|
||||
if (utils.isObject(data) && !utils.isFile(data) && !utils.isBlob(data)) {
|
||||
// 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';
|
||||
}
|
||||
return JSON.stringify(data);
|
||||
|
||||
@@ -56,6 +56,16 @@ function isNumber(val) {
|
||||
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
|
||||
*
|
||||
@@ -182,6 +192,7 @@ module.exports = {
|
||||
isString: isString,
|
||||
isNumber: isNumber,
|
||||
isObject: isObject,
|
||||
isUndefined: isUndefined,
|
||||
isDate: isDate,
|
||||
isFile: isFile,
|
||||
isBlob: isBlob,
|
||||
|
||||
@@ -30,10 +30,7 @@ describe('wrapper', function () {
|
||||
axios({
|
||||
method: 'post',
|
||||
url: '/foo',
|
||||
data: {
|
||||
firstName: 'foo',
|
||||
lastName: 'bar'
|
||||
}
|
||||
data: 'fizz=buzz'
|
||||
});
|
||||
|
||||
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 () {
|
||||
var input = new Int8Array(2);
|
||||
input[0] = 1;
|
||||
|
||||
@@ -19,6 +19,12 @@ module.exports = {
|
||||
test.done();
|
||||
},
|
||||
|
||||
testIsUndefined: function (test) {
|
||||
test.equals(utils.isUndefined(), true);
|
||||
test.equals(utils.isUndefined(null), false);
|
||||
test.done();
|
||||
},
|
||||
|
||||
testIsObject: function (test) {
|
||||
test.equals(utils.isObject({}), true);
|
||||
test.equals(utils.isObject(null), false);
|
||||
|
||||
Reference in New Issue
Block a user