Skip to content

Commit 4113a5f

Browse files
committed
[Tests] clean up stringify tests slightly
1 parent 749a584 commit 4113a5f

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

test/stringify.js

+29-13
Original file line numberDiff line numberDiff line change
@@ -132,42 +132,52 @@ test('stringify()', function (t) {
132132
});
133133

134134
t.test('stringifies a nested array value', function (st) {
135-
st.equal(qs.stringify({ a: { b: ['c', 'd'] } }, { arrayFormat: 'indices' }), 'a%5Bb%5D%5B0%5D=c&a%5Bb%5D%5B1%5D=d');
136-
st.equal(qs.stringify({ a: { b: ['c', 'd'] } }, { arrayFormat: 'brackets' }), 'a%5Bb%5D%5B%5D=c&a%5Bb%5D%5B%5D=d');
137-
st.equal(qs.stringify({ a: { b: ['c', 'd'] } }, { arrayFormat: 'comma' }), 'a%5Bb%5D=c%2Cd'); // a[b]=c,d
138-
st.equal(qs.stringify({ a: { b: ['c', 'd'] } }), 'a%5Bb%5D%5B0%5D=c&a%5Bb%5D%5B1%5D=d');
135+
st.equal(qs.stringify({ a: { b: ['c', 'd'] } }, { encodeValuesOnly: true, arrayFormat: 'indices' }), 'a[b][0]=c&a[b][1]=d');
136+
st.equal(qs.stringify({ a: { b: ['c', 'd'] } }, { encodeValuesOnly: true, arrayFormat: 'brackets' }), 'a[b][]=c&a[b][]=d');
137+
st.equal(qs.stringify({ a: { b: ['c', 'd'] } }, { encodeValuesOnly: true, arrayFormat: 'comma' }), 'a[b]=c%2Cd');
138+
st.equal(qs.stringify({ a: { b: ['c', 'd'] } }, { encodeValuesOnly: true, arrayFormat: 'comma' }), 'a[b]=c,d', '(pending issue #378)', { skip: true });
139+
st.equal(qs.stringify({ a: { b: ['c', 'd'] } }, { encodeValuesOnly: true }), 'a[b][0]=c&a[b][1]=d');
139140
st.end();
140141
});
141142

142143
t.test('stringifies a nested array value with dots notation', function (st) {
143144
st.equal(
144145
qs.stringify(
145146
{ a: { b: ['c', 'd'] } },
146-
{ allowDots: true, encode: false, arrayFormat: 'indices' }
147+
{ allowDots: true, encodeValuesOnly: true, arrayFormat: 'indices' }
147148
),
148149
'a.b[0]=c&a.b[1]=d',
149150
'indices: stringifies with dots + indices'
150151
);
151152
st.equal(
152153
qs.stringify(
153154
{ a: { b: ['c', 'd'] } },
154-
{ allowDots: true, encode: false, arrayFormat: 'brackets' }
155+
{ allowDots: true, encodeValuesOnly: true, arrayFormat: 'brackets' }
155156
),
156157
'a.b[]=c&a.b[]=d',
157158
'brackets: stringifies with dots + brackets'
158159
);
159160
st.equal(
160161
qs.stringify(
161162
{ a: { b: ['c', 'd'] } },
162-
{ allowDots: true, encode: false, arrayFormat: 'comma' }
163+
{ allowDots: true, encodeValuesOnly: true, arrayFormat: 'comma' }
163164
),
164-
'a.b=c,d',
165+
'a.b=c%2Cd',
165166
'comma: stringifies with dots + comma'
166167
);
167168
st.equal(
168169
qs.stringify(
169170
{ a: { b: ['c', 'd'] } },
170-
{ allowDots: true, encode: false }
171+
{ allowDots: true, encodeValuesOnly: true, arrayFormat: 'comma' }
172+
),
173+
'a.b=c,d',
174+
'comma: stringifies with dots + comma (pending issue #378)',
175+
{ skip: true }
176+
);
177+
st.equal(
178+
qs.stringify(
179+
{ a: { b: ['c', 'd'] } },
180+
{ allowDots: true, encodeValuesOnly: true }
171181
),
172182
'a.b[0]=c&a.b[1]=d',
173183
'default: stringifies with dots + indices'
@@ -215,17 +225,23 @@ test('stringify()', function (t) {
215225

216226
t.test('stringifies an array with mixed objects and primitives', function (st) {
217227
st.equal(
218-
qs.stringify({ a: [{ b: 1 }, 2, 3] }, { encode: false, arrayFormat: 'indices' }),
228+
qs.stringify({ a: [{ b: 1 }, 2, 3] }, { encodeValuesOnly: true, arrayFormat: 'indices' }),
219229
'a[0][b]=1&a[1]=2&a[2]=3',
220230
'indices => indices'
221231
);
222232
st.equal(
223-
qs.stringify({ a: [{ b: 1 }, 2, 3] }, { encode: false, arrayFormat: 'brackets' }),
233+
qs.stringify({ a: [{ b: 1 }, 2, 3] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }),
224234
'a[][b]=1&a[]=2&a[]=3',
225235
'brackets => brackets'
226236
);
227237
st.equal(
228-
qs.stringify({ a: [{ b: 1 }, 2, 3] }, { encode: false }),
238+
qs.stringify({ a: [{ b: 1 }, 2, 3] }, { encodeValuesOnly: true, arrayFormat: 'comma' }),
239+
'???',
240+
'brackets => brackets (pending issue #378)',
241+
{ skip: true }
242+
);
243+
st.equal(
244+
qs.stringify({ a: [{ b: 1 }, 2, 3] }, { encodeValuesOnly: true }),
229245
'a[0][b]=1&a[1]=2&a[2]=3',
230246
'default => indices'
231247
);
@@ -784,7 +800,7 @@ test('stringify()', function (t) {
784800
st.equal(qs.stringify(withArray, { encode: false }), 'a[b][0][c]=d&a[b][0][e]=f', 'array, no arrayFormat');
785801
st.equal(qs.stringify(withArray, { encode: false, arrayFormat: 'bracket' }), 'a[b][0][c]=d&a[b][0][e]=f', 'array, bracket');
786802
st.equal(qs.stringify(withArray, { encode: false, arrayFormat: 'indices' }), 'a[b][0][c]=d&a[b][0][e]=f', 'array, indices');
787-
st.equal(qs.stringify(obj, { encode: false, arrayFormat: 'comma' }), '???', 'array, comma (pending issue #378)', { skip: true });
803+
st.equal(qs.stringify(withArray, { encode: false, arrayFormat: 'comma' }), '???', 'array, comma (pending issue #378)', { skip: true });
788804

789805
st.end();
790806
});

0 commit comments

Comments
 (0)