From d4f9b41eda4ab1694779f2ace11ab4cea872b2b0 Mon Sep 17 00:00:00 2001 From: Nito Buendia Date: Tue, 11 Sep 2018 23:25:28 +0800 Subject: [PATCH 1/4] Print error message when available With the current set up, error message is only printed out when error name is available. There are situations where the ErrorEvent object does not have a `name` property, but the message is still relevant. For more details see #1594 --- src/core/ExceptionFormatter.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/ExceptionFormatter.js b/src/core/ExceptionFormatter.js index 359a8303..329418ab 100644 --- a/src/core/ExceptionFormatter.js +++ b/src/core/ExceptionFormatter.js @@ -7,6 +7,8 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) { if (error.name && error.message) { message += error.name + ': ' + error.message; + } else if (error.message) { + message += error.message; } else { message += error.toString() + ' thrown'; } From 963b1cca22158b961b390ddd60e28fe307838c06 Mon Sep 17 00:00:00 2001 From: Nito Buendia Date: Thu, 13 Sep 2018 19:48:10 +0800 Subject: [PATCH 2/4] Add tests for new unnamed errors. --- spec/core/ExceptionFormatterSpec.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/core/ExceptionFormatterSpec.js b/spec/core/ExceptionFormatterSpec.js index 95a476b0..8596f6b9 100644 --- a/spec/core/ExceptionFormatterSpec.js +++ b/spec/core/ExceptionFormatterSpec.js @@ -37,6 +37,15 @@ describe("ExceptionFormatter", function() { expect(message).toEqual('A Classic Mistake: you got your foo in my bar'); }); + it('formats thrown exceptions with message but no name', function() { + var unnamedError = {message: 'This is an unnamed error message.'}; + + exceptionFormatter = new jasmineUnderTest.ExceptionFormatter(), + message = exceptionFormatter.message(unnamedError); + + expect(message).toEqual('This is an unnamed error message.'); + }); + it("formats thrown exceptions that aren't errors", function() { var thrown = "crazy error", exceptionFormatter = new jasmineUnderTest.ExceptionFormatter(), From b4cd1ec1aea83f4615e4ce0d3c6802a44c57ff1a Mon Sep 17 00:00:00 2001 From: Nito Buendia Date: Thu, 13 Sep 2018 19:48:53 +0800 Subject: [PATCH 3/4] Format according to style. --- spec/core/ExceptionFormatterSpec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/core/ExceptionFormatterSpec.js b/spec/core/ExceptionFormatterSpec.js index 8596f6b9..346d4c2a 100644 --- a/spec/core/ExceptionFormatterSpec.js +++ b/spec/core/ExceptionFormatterSpec.js @@ -40,8 +40,8 @@ describe("ExceptionFormatter", function() { it('formats thrown exceptions with message but no name', function() { var unnamedError = {message: 'This is an unnamed error message.'}; - exceptionFormatter = new jasmineUnderTest.ExceptionFormatter(), - message = exceptionFormatter.message(unnamedError); + var exceptionFormatter = new jasmineUnderTest.ExceptionFormatter(), + message = exceptionFormatter.message(unnamedError); expect(message).toEqual('This is an unnamed error message.'); }); From 04679622b08efe9f7745159093ef7d722881df76 Mon Sep 17 00:00:00 2001 From: Nito Buendia Date: Thu, 13 Sep 2018 20:02:30 +0800 Subject: [PATCH 4/4] Add tests for formatting empty content errors. --- spec/core/ExceptionFormatterSpec.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/spec/core/ExceptionFormatterSpec.js b/spec/core/ExceptionFormatterSpec.js index 346d4c2a..9cc3638b 100644 --- a/spec/core/ExceptionFormatterSpec.js +++ b/spec/core/ExceptionFormatterSpec.js @@ -37,7 +37,7 @@ describe("ExceptionFormatter", function() { expect(message).toEqual('A Classic Mistake: you got your foo in my bar'); }); - it('formats thrown exceptions with message but no name', function() { + it('formats unnamed exceptions with message', function() { var unnamedError = {message: 'This is an unnamed error message.'}; var exceptionFormatter = new jasmineUnderTest.ExceptionFormatter(), @@ -46,6 +46,19 @@ describe("ExceptionFormatter", function() { expect(message).toEqual('This is an unnamed error message.'); }); + it('formats empty exceptions with toString format', function() { + var EmptyError = function() {}; + EmptyError.prototype.toString = function() { + return '[EmptyError]'; + }; + var emptyError = new EmptyError(); + + var exceptionFormatter = new jasmineUnderTest.ExceptionFormatter(), + message = exceptionFormatter.message(emptyError); + + expect(message).toEqual('[EmptyError] thrown'); + }); + it("formats thrown exceptions that aren't errors", function() { var thrown = "crazy error", exceptionFormatter = new jasmineUnderTest.ExceptionFormatter(),