Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

add: prevent diffs for differing types. Closes #900

TJ Holowaychuk92d21affdec2
diff --git a/lib/reporters/base.js b/lib/reporters/base.js
index 1ce2e75e..35c90916 100644
--- a/lib/reporters/base.js
+++ b/lib/reporters/base.js
@@ -167,7 +167,7 @@ exports.list = function(failures){
}
// explicitly show diff
- if (err.showDiff) {
+ if (err.showDiff && sameType(actual, expected)) {
escape = false;
err.actual = actual = stringify(actual);
err.expected = expected = stringify(expected);
@@ -384,3 +384,18 @@ function stringify(obj) {
if (obj instanceof RegExp) return obj.toString();
return JSON.stringify(obj, null, 2);
}
+
+/**
+ * Check that a / b have the same type.
+ *
+ * @param {Object} a
+ * @param {Object} b
+ * @return {Boolean}
+ * @api private
+ */
+
+function sameType(a, b) {
+ a = Object.prototype.toString.call(a);
+ b = Object.prototype.toString.call(b);
+ return a == b;
+}