Skip to content

Commit

Permalink
[Tests] stringify: add tests for #378
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jan 13, 2021
1 parent da6d249 commit 66202e7
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,5 +772,22 @@ test('stringify()', function (t) {
st.end();
});

t.test('objects inside arrays', function (st) {
var obj = { a: { b: { c: 'd', e: 'f' } } };
var withArray = { a: { b: [{ c: 'd', e: 'f' }] } };

st.equal(qs.stringify(obj, { encode: false }), 'a[b][c]=d&a[b][e]=f', 'no array, no arrayFormat');
st.equal(qs.stringify(obj, { encode: false, arrayFormat: 'bracket' }), 'a[b][c]=d&a[b][e]=f', 'no array, bracket');
st.equal(qs.stringify(obj, { encode: false, arrayFormat: 'indices' }), 'a[b][c]=d&a[b][e]=f', 'no array, indices');
st.equal(qs.stringify(obj, { encode: false, arrayFormat: 'comma' }), 'a[b][c]=d&a[b][e]=f', 'no array, comma');

st.equal(qs.stringify(withArray, { encode: false }), 'a[b][0][c]=d&a[b][0][e]=f', 'array, no arrayFormat');
st.equal(qs.stringify(withArray, { encode: false, arrayFormat: 'bracket' }), 'a[b][0][c]=d&a[b][0][e]=f', 'array, bracket');
st.equal(qs.stringify(withArray, { encode: false, arrayFormat: 'indices' }), 'a[b][0][c]=d&a[b][0][e]=f', 'array, indices');
st.equal(qs.stringify(obj, { encode: false, arrayFormat: 'comma' }), '???', 'array, comma (pending issue #378)', { skip: true });

st.end();
});

t.end();
});

0 comments on commit 66202e7

Please sign in to comment.