summaryrefslogtreecommitdiff
path: root/test/parallel/test-querystring.js
diff options
context:
space:
mode:
authorBrian White <mscdex@mscdex.net>2017-02-08 03:05:59 -0500
committerJames M Snell <jasnell@gmail.com>2017-02-13 10:40:45 -0800
commit8bcc1223496e6ae16e2b3b2afddf9ca792625055 (patch)
tree06c1493f21539a245cf1204018754a3508407bfe /test/parallel/test-querystring.js
parentff785fd51792a95281014b5e9b526c6619450dc9 (diff)
downloadandroid-node-v8-8bcc1223496e6ae16e2b3b2afddf9ca792625055.tar.gz
android-node-v8-8bcc1223496e6ae16e2b3b2afddf9ca792625055.tar.bz2
android-node-v8-8bcc1223496e6ae16e2b3b2afddf9ca792625055.zip
test: improve querystring.parse assertion messages
PR-URL: https://github.com/nodejs/node/pull/11234 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Nicu Micleușanu <micnic90@gmail.com>
Diffstat (limited to 'test/parallel/test-querystring.js')
-rw-r--r--test/parallel/test-querystring.js32
1 files changed, 24 insertions, 8 deletions
diff --git a/test/parallel/test-querystring.js b/test/parallel/test-querystring.js
index 04034377fe..3f397577df 100644
--- a/test/parallel/test-querystring.js
+++ b/test/parallel/test-querystring.js
@@ -1,6 +1,7 @@
'use strict';
require('../common');
const assert = require('assert');
+const inspect = require('util').inspect;
// test using assert
const qs = require('querystring');
@@ -126,28 +127,43 @@ assert.strictEqual('918854443121279438895193',
qs.parse('id=918854443121279438895193').id);
-function check(actual, expected) {
+function check(actual, expected, input) {
assert(!(actual instanceof Object));
- assert.deepStrictEqual(Object.keys(actual).sort(),
- Object.keys(expected).sort());
- Object.keys(expected).forEach(function(key) {
- assert.deepStrictEqual(actual[key], expected[key]);
+ const actualKeys = Object.keys(actual).sort();
+ const expectedKeys = Object.keys(expected).sort();
+ let msg;
+ if (typeof input === 'string') {
+ msg = `Input: ${inspect(input)}\n` +
+ `Actual keys: ${inspect(actualKeys)}\n` +
+ `Expected keys: ${inspect(expectedKeys)}`;
+ }
+ assert.deepStrictEqual(actualKeys, expectedKeys, msg);
+ expectedKeys.forEach(function(key) {
+ if (typeof input === 'string') {
+ msg = `Input: ${inspect(input)}\n` +
+ `Key: ${inspect(key)}\n` +
+ `Actual value: ${inspect(actual[key])}\n` +
+ `Expected value: ${inspect(expected[key])}`;
+ } else {
+ msg = undefined;
+ }
+ assert.deepStrictEqual(actual[key], expected[key], msg);
});
}
// test that the canonical qs is parsed properly.
qsTestCases.forEach(function(testCase) {
- check(qs.parse(testCase[0]), testCase[2]);
+ check(qs.parse(testCase[0]), testCase[2], testCase[0]);
});
// test that the colon test cases can do the same
qsColonTestCases.forEach(function(testCase) {
- check(qs.parse(testCase[0], ';', ':'), testCase[2]);
+ check(qs.parse(testCase[0], ';', ':'), testCase[2], testCase[0]);
});
// test the weird objects, that they get parsed properly
qsWeirdObjects.forEach(function(testCase) {
- check(qs.parse(testCase[1]), testCase[2]);
+ check(qs.parse(testCase[1]), testCase[2], testCase[1]);
});
qsNoMungeTestCases.forEach(function(testCase) {