From fd3cd7ac2c76b615b554bcd90288ff3a71302d5b Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 12 Apr 2024 10:51:53 -0700 Subject: [PATCH] [Tests] increase coverage --- test/stringify.js | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/test/stringify.js b/test/stringify.js index ea3d0abd..22fcfda2 100644 --- a/test/stringify.js +++ b/test/stringify.js @@ -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 @@ -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(); });