mirror of
https://github.com/tenrok/axios.git
synced 2026-05-15 11:59:42 +03:00
feat: added custom params serializer support; (#5113)
* Added custom params serializer support; * Added missed semicolon; Fixed allowUnknown option; Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
@@ -63,4 +63,20 @@ describe('helpers::buildURL', function () {
|
||||
it('should support URLSearchParams', function () {
|
||||
expect(buildURL('/foo', new URLSearchParams('bar=baz'))).toEqual('/foo?bar=baz');
|
||||
});
|
||||
|
||||
it('should support custom serialize function', function () {
|
||||
const params = {
|
||||
x: 1
|
||||
}
|
||||
|
||||
const options = {
|
||||
serialize: (thisParams, thisOptions) => {
|
||||
expect(thisParams).toEqual(params);
|
||||
expect(thisOptions).toEqual(options);
|
||||
return "rendered"
|
||||
}
|
||||
};
|
||||
|
||||
expect(buildURL('/foo', params, options)).toEqual('/foo?rendered');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -21,7 +21,8 @@ const config: AxiosRequestConfig = {
|
||||
params: { id: 12345 },
|
||||
paramsSerializer: {
|
||||
indexes: true,
|
||||
encode: (value) => value
|
||||
encode: (value) => value,
|
||||
serialize: (value, options) => String(value)
|
||||
},
|
||||
data: { foo: 'bar' },
|
||||
timeout: 10000,
|
||||
|
||||
Reference in New Issue
Block a user