-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathstringify.js
More file actions
39 lines (33 loc) · 1.19 KB
/
Copy pathstringify.js
File metadata and controls
39 lines (33 loc) · 1.19 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
var query = require('querystring');
describe('.stringify(obj)', function(){
describe('when the object is empty', function(){
it('should return ""', function(){
expect(query.stringify({})).to.eql('');
})
})
describe('when a non-object is given', function(){
it('should return ""', function(){
expect(query.stringify(null)).to.eql('');
expect(query.stringify(undefined)).to.eql('');
expect(query.stringify(0)).to.eql('');
expect(query.stringify()).to.eql('');
expect(query.stringify('')).to.eql('');
})
})
describe('when an object is given', function(){
it('should return a query-string', function(){
expect(query.stringify({ name: 'tobi', species: 'ferret' }))
.to.eql('name=tobi&species=ferret');
})
it('should uri encode', function(){
expect(query.stringify({ 'some thing': 'something else' }))
.to.eql('some%20thing=something%20else')
})
})
describe('when object with arrays is given', function(){
it('should return a querystring', function(){
expect(query.stringify({ items: [1, 2, 3], key: 'b' }))
.to.eql('items%5B0%5D=1&items%5B1%5D=2&items%5B2%5D=3&key=b');
})
})
})