forked from sindresorhus/query-string
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringify.js
More file actions
33 lines (27 loc) · 1.11 KB
/
Copy pathstringify.js
File metadata and controls
33 lines (27 loc) · 1.11 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
import test from 'ava';
import fn from '../';
test('stringify', t => {
t.same(fn.stringify({foo: 'bar'}), 'foo=bar');
t.same(fn.stringify({foo: 'bar', bar: 'baz'}), 'foo=bar&bar=baz');
});
test('different types', t => {
t.same(fn.stringify(), '');
t.same(fn.stringify(0), '');
});
test('URI encode', t => {
// jquery.param encodes spaces as + and does not encode a few other characters that strict-uri-encode does.
t.same(fn.stringify({'foo bar': 'baz faz'}), 'foo+bar=baz+faz');
t.same(fn.stringify({'foo bar': 'baz\'faz'}), 'foo+bar=baz\'faz');
});
test('handle array value', t => {
t.same(fn.stringify({abc: 'abc', foo: ['bar', 'baz']}), 'abc=abc&foo=bar&foo=baz');
// jquery.param encodes null and undefined as empty strings
t.same(fn.stringify({abc: 'abc', foo: [null, 'baz']}), 'abc=abc&foo=&foo=baz');
});
test('handle empty array value', t => {
t.same(fn.stringify({abc: 'abc', foo: []}), 'abc=abc');
});
test('should encode undefined and null values as empty string', t => {
t.same(fn.stringify({abc: undefined, foo: 'bar'}), 'abc=&foo=bar');
t.same(fn.stringify({abc: null, foo: 'bar'}), 'abc=&foo=bar');
});