diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 215b6b59..99236bb1 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -2851,6 +2851,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'; } diff --git a/spec/core/ExceptionFormatterSpec.js b/spec/core/ExceptionFormatterSpec.js index 95a476b0..9cc3638b 100644 --- a/spec/core/ExceptionFormatterSpec.js +++ b/spec/core/ExceptionFormatterSpec.js @@ -37,6 +37,28 @@ describe("ExceptionFormatter", function() { expect(message).toEqual('A Classic Mistake: you got your foo in my bar'); }); + it('formats unnamed exceptions with message', function() { + var unnamedError = {message: 'This is an unnamed error message.'}; + + var exceptionFormatter = new jasmineUnderTest.ExceptionFormatter(), + message = exceptionFormatter.message(unnamedError); + + 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(), 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'; }