2
0
mirror of https://github.com/tenrok/axios.git synced 2026-05-27 14:47:43 +03:00
Files
axios/test/specs/helpers/buildURL.spec.js
T
Dmitriy Mozgovoy 934f390cc3 URL params serializer; (#4734)
* Refactored BuildURL helper to use URLSearchParams serializer;

* Updated typings;
Added TS test;
2022-05-25 08:16:38 +02:00

67 lines
1.7 KiB
JavaScript

var buildURL = require('../../../lib/helpers/buildURL');
var URLSearchParams = require('url-search-params');
describe('helpers::buildURL', function () {
it('should support null params', function () {
expect(buildURL('/foo')).toEqual('/foo');
});
it('should support params', function () {
expect(buildURL('/foo', {
foo: 'bar'
})).toEqual('/foo?foo=bar');
});
it('should support object params', function () {
expect(buildURL('/foo', {
foo: {
bar: 'baz'
}
})).toEqual('/foo?foo[bar]=baz');
});
it('should support date params', function () {
var date = new Date();
expect(buildURL('/foo', {
date: date
})).toEqual('/foo?date=' + date.toISOString());
});
it('should support array params', function () {
expect(buildURL('/foo', {
foo: ['bar', 'baz']
})).toEqual('/foo?foo[]=bar&foo[]=baz');
});
it('should support special char params', function () {
expect(buildURL('/foo', {
foo: ':$, '
})).toEqual('/foo?foo=:$,+');
});
it('should support existing params', function () {
expect(buildURL('/foo?foo=bar', {
bar: 'baz'
})).toEqual('/foo?foo=bar&bar=baz');
});
it('should support "length" parameter', function () {
expect(buildURL('/foo', {
query: 'bar',
start: 0,
length: 5
})).toEqual('/foo?query=bar&start=0&length=5');
});
it('should correct discard url hash mark', function () {
expect(buildURL('/foo?foo=bar#hash', {
query: 'baz'
})).toEqual('/foo?foo=bar&query=baz');
});
it('should support URLSearchParams', function () {
expect(buildURL('/foo', new URLSearchParams('bar=baz'))).toEqual('/foo?bar=baz');
});
});