Skip to content

Commit

Permalink
[Tests] increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Apr 12, 2024
1 parent 6d7df02 commit fd3cd7a
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion test/stringify.js
Expand Up @@ -163,7 +163,17 @@ test('stringify()', function (t) {
st.end();
});

t.test('should throw when encodeDotInKeys is not of type boolean', function (st) {
t.test('throws when `commaRoundTrip` is not a boolean', function (st) {
st['throws'](
function () { qs.stringify({}, { commaRoundTrip: 'not a boolean' }); },
TypeError,
'throws when `commaRoundTrip` is not a boolean'
);

st.end();
});

t.test('throws when `encodeDotInKeys` is not a boolean', function (st) {
st['throws'](
function () { qs.stringify({ a: [], b: 'zz' }, { encodeDotInKeys: 'foobar' }); },
TypeError
Expand Down Expand Up @@ -1218,6 +1228,27 @@ test('stringify()', function (t) {
st.end();
});

t.test('encodes a very long string', function (st) {
var chars = [];
var expected = [];
for (var i = 0; i < 5e3; i++) {
chars.push(' ' + i);

expected.push('%20' + i);
}

var obj = {
foo: chars.join('')
};

st.equal(
qs.stringify(obj, { arrayFormat: 'bracket', charset: 'utf-8' }),
'foo=' + expected.join('')
);

st.end();
});

t.end();
});

Expand Down

0 comments on commit fd3cd7a

Please sign in to comment.