mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
fix: allow passing a callback as paramsSerializer to buildURL (#6680)
* fix: allow passing a callback as paramsSerializer to buildURL * fix: add missing semicolon
This commit is contained in:
@@ -26,7 +26,7 @@ function encode(val) {
|
|||||||
*
|
*
|
||||||
* @param {string} url The base of the url (e.g., http://www.google.com)
|
* @param {string} url The base of the url (e.g., http://www.google.com)
|
||||||
* @param {object} [params] The params to be appended
|
* @param {object} [params] The params to be appended
|
||||||
* @param {?object} options
|
* @param {?(object|Function)} options
|
||||||
*
|
*
|
||||||
* @returns {string} The formatted url
|
* @returns {string} The formatted url
|
||||||
*/
|
*/
|
||||||
@@ -38,6 +38,12 @@ export default function buildURL(url, params, options) {
|
|||||||
|
|
||||||
const _encode = options && options.encode || encode;
|
const _encode = options && options.encode || encode;
|
||||||
|
|
||||||
|
if (utils.isFunction(options)) {
|
||||||
|
options = {
|
||||||
|
serialize: options
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const serializeFn = options && options.serialize;
|
const serializeFn = options && options.serialize;
|
||||||
|
|
||||||
let serializedParams;
|
let serializedParams;
|
||||||
|
|||||||
@@ -98,5 +98,12 @@ describe('helpers::buildURL', function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
expect(buildURL('/foo', params, options)).toEqual('/foo?rendered');
|
expect(buildURL('/foo', params, options)).toEqual('/foo?rendered');
|
||||||
|
|
||||||
|
const customSerializer = (thisParams) => {
|
||||||
|
expect(thisParams).toEqual(params);
|
||||||
|
return "rendered"
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(buildURL('/foo', params, customSerializer)).toEqual('/foo?rendered');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user