-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathparse.js
More file actions
52 lines (44 loc) · 1.63 KB
/
Copy pathparse.js
File metadata and controls
52 lines (44 loc) · 1.63 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
42
43
44
45
46
47
48
49
50
51
52
var query = require('querystring');
describe('.parse(str)', function(){
describe('when the string is empty', function(){
it('should return {}', function(){
expect(query.parse('')).to.eql({});
})
})
describe('when a non-string is passed', function(){
it('should return {}', function(){
expect(query.parse(null)).to.eql({});
expect(query.parse(0)).to.eql({});
expect(query.parse()).to.eql({});
})
})
describe('when a querystring value with spaces encoded as "+" is passed', function(){
it('should decode them to spaces', function(){
expect(query.parse('?names=friends+and+family')).to.eql({ names: 'friends and family' });
})
})
describe('when values are omitted', function(){
it('should default values to ""', function(){
var obj = query.parse('name&species');
expect(obj).to.eql({ name: '', species: '' });
})
})
describe('when values are present', function(){
it('should parse map the key / value pairs', function(){
var obj = query.parse('name=tobi&species=ferret');
expect(obj).to.eql({ name: 'tobi', species: 'ferret' });
})
})
describe('when the string includes a question-mark', function(){
it('should remove the question-mark', function(){
var obj = query.parse('?name=tobi&species=ferret');
expect(obj).to.eql({ name: 'tobi', species: 'ferret' });
})
})
describe('when querystring array is given', function(){
it('should parse as array', function(){
var obj = query.parse('items%5B0%5D=1&items%5B1%5D=2&items%5B2%5D=3&key=a');
expect(obj).to.eql({ items: [1, 2, 3], key: 'a' });
})
})
})