summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jstests/noPassthrough/shell_assertions.js19
-rw-r--r--src/mongo/shell/assert.js6
2 files changed, 23 insertions, 2 deletions
diff --git a/jstests/noPassthrough/shell_assertions.js b/jstests/noPassthrough/shell_assertions.js
index 8915d087a3e..88fdcaa79ab 100644
--- a/jstests/noPassthrough/shell_assertions.js
+++ b/jstests/noPassthrough/shell_assertions.js
@@ -133,6 +133,25 @@
assert.eq(true, called, 'called should not have been udpated');
});
+ tests.push(function assertShouldAcceptObjectAsMsg() {
+ const objMsg = {someMessage: 1};
+ const err = assert.throws(() => {
+ assert(false, objMsg);
+ });
+
+ assert.neq(-1,
+ err.message.indexOf(tojson(objMsg)),
+ 'Error message should have included ' + tojson(objMsg));
+ });
+
+ tests.push(function assertShouldNotAcceptNonObjStringFunctionAsMsg() {
+ const err = assert.throws(() => {
+ assert(true, 1234);
+ });
+
+ assert.neq(-1, err.message.indexOf("msg parameter must be a "));
+ });
+
/* assert.automsg tests */
tests.push(function automsgShouldPassToAssert() {
diff --git a/src/mongo/shell/assert.js b/src/mongo/shell/assert.js
index fa5e18dfe72..24677f96349 100644
--- a/src/mongo/shell/assert.js
+++ b/src/mongo/shell/assert.js
@@ -97,6 +97,8 @@ assert = (function() {
function _processMsg(msg) {
if (typeof msg === "function") {
return msg();
+ } else if (typeof msg === "object") {
+ return tojson(msg);
}
return msg;
@@ -108,8 +110,8 @@ assert = (function() {
if (msg.length !== 0) {
doassert("msg function cannot expect any parameters.");
}
- } else if (typeof msg !== "string") {
- doassert("msg parameter must be a string or a function.");
+ } else if (typeof msg !== "string" && typeof msg !== "object") {
+ doassert("msg parameter must be a string, function or object.");
}
if (msg && assert._debug) {