☕️ Classic, reliable, trusted test framework for Node.js and the browser
fix(reporter/base): don't show diffs for errors without expectation
Maximilian Antoni18d2e05253f0
diff --git a/lib/reporters/base.js b/lib/reporters/base.jsindex 19637a91..c3ffe6a9 100644--- a/lib/reporters/base.js+++ b/lib/reporters/base.js@@ -186,7 +186,8 @@ exports.list = function(failures){msg = 'Uncaught ' + msg;}// explicitly show diff- if (err.showDiff !== false && sameType(actual, expected)) {+ if (err.showDiff !== false && sameType(actual, expected)+ && expected !== undefined) {if ('string' !== typeof actual) {escape = false;diff --git a/test/reporters/base.js b/test/reporters/base.jsindex 57c0d168..3b06f34a 100644--- a/test/reporters/base.js+++ b/test/reporters/base.js@@ -40,8 +40,8 @@ describe('Base reporter', function () {Base.list([test]);errOut = stdout.join('\n');- errOut.should.match(/actual/);- errOut.should.match(/expected/);+ errOut.should.match(/\- actual/);+ errOut.should.match(/\+ expected/);});it('should show diffs if property set to `true`', function () {@@ -55,8 +55,8 @@ describe('Base reporter', function () {Base.list([test]);errOut = stdout.join('\n');- errOut.should.match(/actual/);- errOut.should.match(/expected/);+ errOut.should.match(/\- actual/);+ errOut.should.match(/\+ expected/);});it('should not show diffs when showDiff property set to `false`', function () {@@ -69,9 +69,23 @@ describe('Base reporter', function () {Base.list([test]);errOut = stdout.join('\n');- errOut.should.not.match(/actual/);- errOut.should.not.match(/expected/);+ errOut.should.not.match(/\- actual/);+ errOut.should.not.match(/\+ expected/);});++ it('should not show diffs when expected is not defined', function () {+ var err = new Error('ouch')+ , errOut;++ var test = makeTest(err);++ Base.list([test]);++ errOut = stdout.join('\n');+ errOut.should.not.match(/\- actual/);+ errOut.should.not.match(/\+ expected/);+ });+});it('should not stringify strings', function () {@@ -88,8 +102,8 @@ describe('Base reporter', function () {errOut = stdout.join('\n');errOut.should.not.match(/"/);errOut.should.match(/test/);- errOut.should.match(/actual/);- errOut.should.match(/expected/);+ errOut.should.match(/\- actual/);+ errOut.should.match(/\+ expected/);});it('should stringify objects', function () {@@ -106,8 +120,8 @@ describe('Base reporter', function () {errOut = stdout.join('\n');errOut.should.match(/"key"/);errOut.should.match(/test/);- errOut.should.match(/actual/);- errOut.should.match(/expected/);+ errOut.should.match(/\- actual/);+ errOut.should.match(/\+ expected/);});it('should remove message from stack', function () {