Skip to content

Commit

Permalink
[Tests] parse: add passing arrayFormat tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dreyks authored and ljharb committed Sep 8, 2019
1 parent df0cb44 commit 4751fc0
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/parse.js
Expand Up @@ -32,6 +32,24 @@ test('parse()', function (t) {
st.end();
});

t.test('arrayFormat: brackets allows only explicit arrays', function (st) {
st.deepEqual(qs.parse('a[]=b&a[]=c', { arrayFormat: 'brackets' }), { a: ['b', 'c'] });
st.deepEqual(qs.parse('a=b,c', { arrayFormat: 'brackets' }), { a: 'b,c' });
st.end();
});

t.test('arrayFormat: indices allows only indexed arrays', function (st) {
st.deepEqual(qs.parse('a[0]=b&a[1]=c', { arrayFormat: 'indices' }), { a: ['b', 'c'] });
st.deepEqual(qs.parse('a=b,c', { arrayFormat: 'indices' }), { a: 'b,c' });
st.end();
});

t.test('arrayFormat: repeat allows only repeated values', function (st) {
st.deepEqual(qs.parse('a=b,c', { arrayFormat: 'repeat' }), { a: 'b,c' });
st.deepEqual(qs.parse('a=b&a=c', { arrayFormat: 'repeat' }), { a: ['b', 'c'] });
st.end();
});

t.test('allows enabling dot notation', function (st) {
st.deepEqual(qs.parse('a.b=c'), { 'a.b': 'c' });
st.deepEqual(qs.parse('a.b=c', { allowDots: true }), { a: { b: 'c' } });
Expand Down

0 comments on commit 4751fc0

Please sign in to comment.