source: trip-planner-front/node_modules/needle/test/querystring_spec.js@ fa375fe

Last change on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.3 KB
Line 
1var should = require('should'),
2 stringify = require('../lib/querystring').build;
3
4describe('stringify', function() {
5
6 describe('with null', function() {
7
8 it('throws', function() {
9 (function() {
10 var res = stringify(null);
11 }).should.throw();
12 })
13
14 })
15
16 describe('with a number', function() {
17
18 it('throws', function() {
19 (function() {
20 var res = stringify(100);
21 }).should.throw();
22 })
23
24 })
25
26 describe('with a string', function() {
27
28 describe('that is empty', function() {
29
30 it('throws', function() {
31 (function() {
32 var res = stringify('');
33 }).should.throw();
34 })
35
36 })
37
38 describe('that doesnt contain an equal sign', function() {
39
40 it('throws', function() {
41 (function() {
42 var res = stringify('boomshagalaga');
43 }).should.throw();
44 })
45
46 })
47
48 describe('that contains an equal sign', function() {
49
50 it('works', function() {
51 var res = stringify('hello=123');
52 res.should.eql('hello=123');
53 })
54
55 })
56
57 })
58
59 describe('with an array', function() {
60
61 describe('with key val objects', function() {
62
63 it('works', function() {
64 var res = stringify([ {foo: 'bar'} ]);
65 res.should.eql('foo=bar');
66 })
67
68 })
69
70 describe('where all elements are strings with an equal sign', function() {
71
72 it('works', function() {
73 var res = stringify([ 'bar=123', 'quux=' ]);
74 res.should.eql('bar=123&quux=');
75 })
76
77 })
78
79 describe('with random words', function() {
80
81 it('throws', function() {
82 (function() {
83 var res = stringify(['hello', 'there']);
84 }).should.throw();
85 })
86
87 })
88
89 describe('with integers', function() {
90
91 it('throws', function() {
92 (function() {
93 var res = stringify([123, 432]);
94 }).should.throw();
95 })
96
97 })
98
99 })
100
101 describe('with an object', function() {
102
103 it('works', function() {
104 var res = stringify({ test: 100 });
105 res.should.eql('test=100');
106 })
107
108 describe('with object where val is an array', function() {
109
110 it('works', function() {
111 var res = stringify({ foo: ['bar', 'baz'] });
112 res.should.eql('foo[]=bar&foo[]=baz');
113 })
114
115 })
116
117 describe('with object where val is an array of key val objects', function() {
118
119 it('works', function() {
120 var res = stringify({ foo: [{'1': 'bar'}, {'2': 'baz'}] });
121 res.should.eql('foo[][1]=bar&foo[][2]=baz');
122 })
123
124 })
125
126 })
127
128})
Note: See TracBrowser for help on using the repository browser.