-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathquery-params.test.js
More file actions
41 lines (34 loc) · 1.46 KB
/
query-params.test.js
File metadata and controls
41 lines (34 loc) · 1.46 KB
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
/* jshint maxlen: 99999 */
var params = require('./index.js');
describe('query-params', function() {
var URL = 'http://some.domain.com/foo|3.0|123.1|456|7|BAR;foo=bar;a=1;b=+B;¶m=test';
it('should encode object to url-string', function () {
expect(params.encode({a: 'a', b: 'b', c: 'c', d: 'd', e: 'e'})).toEqual('a=a&b=b&c=c&d=d&e=e');
expect(params.encode({a: 'a'})).toEqual('a=a');
expect(params.encode({a: 'æ'})).toEqual('a=%C3%A6');
expect(params.encode({a: 1})).toEqual('a=1');
expect(params.encode({a: URL})).toEqual('a=' + encodeURIComponent(URL));
});
it('should encode with custom separator', function () {
expect(params.encode({a: 'a', b: 'b'}, ';')).toEqual('a=a;b=b');
});
it('should decode url-string to an object', function(){
expect(params.decode('a=a&b=b&c=c&d=d;e=e')).toEqual({a: 'a', b: 'b', c: 'c', d: 'd', e: 'e'});
expect(params.decode('a=æ')).toEqual({a: 'æ'});
expect(params.decode('a=%C3%A6')).toEqual({a: 'æ'});
var urlInUrl = params.encode({
'url': URL,
'width': 123,
'height': 321
});
expect(params.decode(urlInUrl))
.toEqual({
url: URL,
width: '123',
height: '321'
});
});
it('should decode with custom separator', function () {
expect(params.decode('a=1;b=2', ';')).toEqual({a: '1', b: '2'});
});
});