-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
53 lines (40 loc) · 1.16 KB
/
test.js
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
import test from 'ava';
import { stringify, parse } from '.';
test('should return empty string from plain object', t => {
t.is(stringify({}), '')
});
test('should serialize query object to string', t => {
const input = { foo: 1, bar: 2 };
t.is(stringify(input), 'foo=1&bar=2')
});
test('should serialize query object with values of single key', t => {
const input = { foo: 1, bar: [2, 3] };
t.is(stringify(input), 'foo=1&bar=2&bar=3')
});
test('should return empty plain object from empty string', t => {
t.deepEqual(parse(''), {})
});
test('should return empty plain object from string containing only ?', t => {
t.deepEqual(parse('?'), {})
});
test('should deserialize query string to object', t => {
const input = 'foo=1&bar=2';
t.deepEqual(parse(input), {
foo: '1',
bar: '2',
});
});
test('should deserialize query string with ? to object', t => {
const input = '?foo=1&bar=2';
t.deepEqual(parse(input), {
foo: '1',
bar: '2',
});
});
test('should deserialize query string with mutiple instances of the same key', t => {
const input = 'foo=1&bar=2&bar=3';
t.deepEqual(parse(input), {
foo: '1',
bar: ['2', '3'],
});
});