summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/request/node_modules/qs/test/stringify.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/request/node_modules/qs/test/stringify.js')
-rw-r--r--deps/npm/node_modules/request/node_modules/qs/test/stringify.js35
1 files changed, 32 insertions, 3 deletions
diff --git a/deps/npm/node_modules/request/node_modules/qs/test/stringify.js b/deps/npm/node_modules/request/node_modules/qs/test/stringify.js
index 711dae507d..124a99dca4 100644
--- a/deps/npm/node_modules/request/node_modules/qs/test/stringify.js
+++ b/deps/npm/node_modules/request/node_modules/qs/test/stringify.js
@@ -2,6 +2,7 @@
var test = require('tape');
var qs = require('../');
+var utils = require('../lib/utils');
var iconv = require('iconv-lite');
test('stringify()', function (t) {
@@ -17,6 +18,16 @@ test('stringify()', function (t) {
st.end();
});
+ t.test('adds query prefix', function (st) {
+ st.equal(qs.stringify({ a: 'b' }, { addQueryPrefix: true }), '?a=b');
+ st.end();
+ });
+
+ t.test('with query prefix, outputs blank string given an empty object', function (st) {
+ st.equal(qs.stringify({}, { addQueryPrefix: true }), '');
+ st.end();
+ });
+
t.test('stringifies a nested object', function (st) {
st.equal(qs.stringify({ a: { b: 'c' } }), 'a%5Bb%5D=c');
st.equal(qs.stringify({ a: { b: { c: { d: 'e' } } } }), 'a%5Bb%5D%5Bc%5D%5Bd%5D=e');
@@ -452,8 +463,18 @@ test('stringify()', function (t) {
st.end();
});
+ t.test('receives the default encoder as a second argument', function (st) {
+ st.plan(2);
+ qs.stringify({ a: 1 }, {
+ encoder: function (str, defaultEncoder) {
+ st.equal(defaultEncoder, utils.encode);
+ }
+ });
+ st.end();
+ });
+
t.test('throws error with wrong encoder', function (st) {
- st.throws(function () {
+ st['throws'](function () {
qs.stringify({}, { encoder: 'string' });
}, new TypeError('Encoder has to be a function.'));
st.end();
@@ -483,7 +504,7 @@ test('stringify()', function (t) {
mutatedDate.toISOString = function () {
throw new SyntaxError();
};
- st.throws(function () {
+ st['throws'](function () {
mutatedDate.toISOString();
}, SyntaxError);
st.equal(
@@ -525,7 +546,7 @@ test('stringify()', function (t) {
t.test('Edge cases and unknown formats', function (st) {
['UFO1234', false, 1234, null, {}, []].forEach(
function (format) {
- st.throws(
+ st['throws'](
function () {
qs.stringify({ a: 'b c' }, { format: format });
},
@@ -564,4 +585,12 @@ test('stringify()', function (t) {
st.end();
});
+ t.test('does not mutate the options argument', function (st) {
+ var options = {};
+ qs.stringify({}, options);
+ st.deepEqual(options, {});
+ st.end();
+ });
+
+ t.end();
});