From 06a553503d746b7604d3a17196fe8f002e9add3d Mon Sep 17 00:00:00 2001 From: Sheel Choksi Date: Thu, 9 Jan 2014 22:10:40 -0800 Subject: [PATCH] Better failure message when something is thrown that's not an error Change from 'undefined : undefined' to ' thrown' Pointed out by @charleshansen --- lib/jasmine-core/jasmine.js | 10 +++++++--- spec/core/ExceptionFormatterSpec.js | 7 +++++++ src/core/ExceptionFormatter.js | 10 +++++++--- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index d30bef49..e88c3655 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -1129,9 +1129,13 @@ getJasmineRequireObj().DelayedFunctionScheduler = function() { getJasmineRequireObj().ExceptionFormatter = function() { function ExceptionFormatter() { this.message = function(error) { - var message = error.name + - ': ' + - error.message; + var message = ''; + + if (error.name && error.message) { + message += error.name + ': ' + error.message; + } else { + message += error.toString() + ' thrown'; + } if (error.fileName || error.sourceURL) { message += " in " + (error.fileName || error.sourceURL); diff --git a/spec/core/ExceptionFormatterSpec.js b/spec/core/ExceptionFormatterSpec.js index 88d83938..5c4ead71 100644 --- a/spec/core/ExceptionFormatterSpec.js +++ b/spec/core/ExceptionFormatterSpec.js @@ -35,7 +35,14 @@ describe("ExceptionFormatter", function() { message = exceptionFormatter.message(sampleV8); expect(message).toEqual('A Classic Mistake: you got your foo in my bar'); + }); + it("formats thrown exceptions that aren't errors", function() { + var thrown = "crazy error", + exceptionFormatter = new j$.ExceptionFormatter(), + message = exceptionFormatter.message(thrown); + + expect(message).toEqual("crazy error thrown"); }); }); diff --git a/src/core/ExceptionFormatter.js b/src/core/ExceptionFormatter.js index 29e17d46..1af2f75f 100644 --- a/src/core/ExceptionFormatter.js +++ b/src/core/ExceptionFormatter.js @@ -1,9 +1,13 @@ getJasmineRequireObj().ExceptionFormatter = function() { function ExceptionFormatter() { this.message = function(error) { - var message = error.name + - ': ' + - error.message; + var message = ''; + + if (error.name && error.message) { + message += error.name + ': ' + error.message; + } else { + message += error.toString() + ' thrown'; + } if (error.fileName || error.sourceURL) { message += " in " + (error.fileName || error.sourceURL);