Skip to content

armgit / mocha

Public Imported from GitHub
0

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

fix diff for objects with custom hasOwnProperty values

Maximilian Antoniae54df9e16cf
diff --git a/lib/utils.js b/lib/utils.js
index 7a65f92e..5dc41aa3 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -498,7 +498,7 @@ function jsonStringify(object, spaces, depth) {
}
for (var i in object) {
- if (!object.hasOwnProperty(i)) {
+ if (!Object.prototype.hasOwnProperty.call(object, i)) {
continue; // not my business
}
--length;
diff --git a/test/reporters/base.js b/test/reporters/base.js
index e33e26f9..affc7ba2 100644
--- a/test/reporters/base.js
+++ b/test/reporters/base.js
@@ -129,6 +129,26 @@ describe('Base reporter', function () {
errOut.should.match(/\+ expected/);
});
+ it('should stringify Object.create(null)', function () {
+ var err = new Error('test'),
+ errOut;
+
+ err.actual = Object.create(null);
+ err.actual.hasOwnProperty = 1;
+ err.expected = Object.create(null);
+ err.expected.hasOwnProperty = 2;
+ err.showDiff = true;
+ var test = makeTest(err);
+
+ Base.list([test]);
+
+ errOut = stdout.join('\n');
+ errOut.should.match(/"hasOwnProperty"/);
+ errOut.should.match(/test/);
+ errOut.should.match(/\- actual/);
+ errOut.should.match(/\+ expected/);
+ });
+
it('should remove message from stack', function () {
var err = {
message: 'Error',