Skip to content

Commit

Permalink
[Tests] add tests for depth=0 and depth=false behavior, both curr…
Browse files Browse the repository at this point in the history
…ent and intuitive/intended
  • Loading branch information
idler8 authored and ljharb committed Aug 8, 2019
1 parent 360ec16 commit a30e4b1
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,30 @@ test('parse()', function (t) {
st.end();
});

t.test('current behavior with depth = 0', function (st) {
st.deepEqual(qs.parse('a[0]=b&a[1]=c', { depth: 0 }), { a: { '[0]': 'b', '[1]': 'c' } });
st.deepEqual(qs.parse('a[0][0]=b&a[0][1]=c&a[1]=d&e=2', { depth: 0 }), { a: { '[0][0]': 'b', '[0][1]': 'c', '[1]': 'd' }, e: '2' });
st.end();
});

t.test('uses original key when depth = 0', { skip: true, todo: true }, function (st) {
st.deepEqual(qs.parse('a[0]=b&a[1]=c', { depth: 0 }), { 'a[0]': 'b', 'a[1]': 'c' });
st.deepEqual(qs.parse('a[0][0]=b&a[0][1]=c&a[1]=d&e=2', { depth: 0 }), { 'a[0][0]': 'b', 'a[0][1]': 'c', 'a[1]': 'd', e: '2' });
st.end();
});

t.test('current behavior with depth = false', function (st) {
st.deepEqual(qs.parse('a[0]=b&a[1]=c', { depth: false }), { a: ['b', 'c'] });
st.deepEqual(qs.parse('a[0][0]=b&a[0][1]=c&a[1]=d&e=2', { depth: false }), { a: [['b', 'c'], 'd'], e: '2' });
st.end();
});

t.test('uses original key when depth = false', { skip: true, todo: true }, function (st) {
st.deepEqual(qs.parse('a[0]=b&a[1]=c', { depth: false }), { 'a[0]': 'b', 'a[1]': 'c' });
st.deepEqual(qs.parse('a[0][0]=b&a[0][1]=c&a[1]=d&e=2', { depth: false }), { 'a[0][0]': 'b', 'a[0][1]': 'c', 'a[1]': 'd', e: '2' });
st.end();
});

t.deepEqual(qs.parse('a=b&a=c'), { a: ['b', 'c'] }, 'parses a simple array');

t.test('parses an explicit array', function (st) {
Expand Down

0 comments on commit a30e4b1

Please sign in to comment.