mirror of
https://github.com/tenrok/axios.git
synced 2026-06-14 18:42:33 +03:00
Merge pull request #317 from nickuraltsev/urlsearchparams
Adding support for URLSearchParams
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
// Polyfill ES6 Promise
|
||||
require('es6-promise').polyfill();
|
||||
|
||||
// Polyfill URLSearchParams
|
||||
URLSearchParams = require('url-search-params');
|
||||
|
||||
// Import axios
|
||||
axios = require('../../index');
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
var buildURL = require('../../../lib/helpers/buildURL');
|
||||
var URLSearchParams = require('url-search-params');
|
||||
|
||||
describe('helpers::buildURL', function () {
|
||||
it('should support null params', function () {
|
||||
@@ -60,7 +61,9 @@ describe('helpers::buildURL', function () {
|
||||
expect(buildURL('/foo', params, serializer)).toEqual('/foo?foo=bar');
|
||||
expect(serializer.calledOnce).toBe(true);
|
||||
expect(serializer.calledWith(params)).toBe(true);
|
||||
})
|
||||
});
|
||||
|
||||
it('should support URLSearchParams', function () {
|
||||
expect(buildURL('/foo', new URLSearchParams('bar=baz'))).toEqual('/foo?bar=baz');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
var normalizeHeaderName = require('../../../lib/helpers/normalizeHeaderName');
|
||||
|
||||
describe('helpers::normalizeHeaderName', function () {
|
||||
it('should normalize matching header name', function () {
|
||||
var headers = {
|
||||
'conTenT-Type': 'foo/bar',
|
||||
};
|
||||
normalizeHeaderName(headers, 'Content-Type');
|
||||
expect(headers['Content-Type']).toBe('foo/bar');
|
||||
expect(headers['conTenT-Type']).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should not change non-matching header name', function () {
|
||||
var headers = {
|
||||
'content-type': 'foo/bar',
|
||||
};
|
||||
normalizeHeaderName(headers, 'Content-Length');
|
||||
expect(headers['content-type']).toBe('foo/bar');
|
||||
expect(headers['Content-Length']).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -277,4 +277,17 @@ describe('requests', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should support URLSearchParams', function (done) {
|
||||
var params = new URLSearchParams();
|
||||
params.append('param1', 'value1');
|
||||
params.append('param2', 'value2');
|
||||
|
||||
axios.post('/foo', params);
|
||||
|
||||
getAjaxRequest().then(function (request) {
|
||||
expect(request.requestHeaders['Content-Type']).toBe('application/x-www-form-urlencoded;charset=utf-8');
|
||||
expect(request.params).toBe('param1=value1¶m2=value2');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -78,4 +78,9 @@ describe('utils::isX', function () {
|
||||
expect(utils.isStream(new Stream.Readable())).toEqual(true);
|
||||
expect(utils.isStream({ foo: 'bar' })).toEqual(false);
|
||||
});
|
||||
|
||||
it('should validate URLSearchParams', function () {
|
||||
expect(utils.isURLSearchParams(new URLSearchParams())).toEqual(true);
|
||||
expect(utils.isURLSearchParams('foo=1&bar=2')).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user