1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
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=' + encodeURI('{"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 use serializer if provided', function () {
serializer = sinon.stub();
params = {foo: 'bar'};
serializer.returns('foo=bar');
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');
});
});
|