diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index aaa8ec7a..67ebb2a8 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -2498,12 +2498,16 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) { var stackTrace = new j$.StackTrace(error.stack); var lines = filterJasmine(stackTrace); + var result = ''; if (stackTrace.message) { lines.unshift(stackTrace.message); } - return lines.join('\n'); + result += formatProperties(error); + result += lines.join('\n'); + + return result; }; function filterJasmine(stackTrace) { @@ -2520,6 +2524,30 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) { return result; } + + function formatProperties(error) { + if (!(error instanceof Object)) { + return; + } + + var ignored = ['name', 'message', 'stack', 'fileName', 'sourceURL', 'line', 'lineNumber']; + var result = {}; + var empty = true; + + for (var prop in error) { + if (ignored.includes(prop)) { + continue; + } + result[prop] = error[prop]; + empty = false; + } + + if (!empty) { + return 'error properties: ' + j$.pp(result) + '\n'; + } + + return ''; + } } return ExceptionFormatter; diff --git a/spec/core/ExceptionFormatterSpec.js b/spec/core/ExceptionFormatterSpec.js index a7069d3e..e896a5fe 100644 --- a/spec/core/ExceptionFormatterSpec.js +++ b/spec/core/ExceptionFormatterSpec.js @@ -116,5 +116,16 @@ describe("ExceptionFormatter", function() { it("returns null if no Error provided", function() { expect(new jasmineUnderTest.ExceptionFormatter().stack()).toBeNull(); }); + + it("includes error properties in stack", function() { + var error; + try { throw new Error("an error") } catch(e) { error = e; } + error.someProperty = 'hello there'; + + var result = new jasmineUnderTest.ExceptionFormatter().stack(error); + + expect(result).toMatch(/error properties:.*someProperty.*hello there/); + }); + }); }); diff --git a/src/core/ExceptionFormatter.js b/src/core/ExceptionFormatter.js index e6808403..aa3a62ae 100644 --- a/src/core/ExceptionFormatter.js +++ b/src/core/ExceptionFormatter.js @@ -29,12 +29,16 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) { var stackTrace = new j$.StackTrace(error.stack); var lines = filterJasmine(stackTrace); + var result = ''; if (stackTrace.message) { lines.unshift(stackTrace.message); } - return lines.join('\n'); + result += formatProperties(error); + result += lines.join('\n'); + + return result; }; function filterJasmine(stackTrace) { @@ -51,6 +55,30 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) { return result; } + + function formatProperties(error) { + if (!(error instanceof Object)) { + return; + } + + var ignored = ['name', 'message', 'stack', 'fileName', 'sourceURL', 'line', 'lineNumber']; + var result = {}; + var empty = true; + + for (var prop in error) { + if (ignored.includes(prop)) { + continue; + } + result[prop] = error[prop]; + empty = false; + } + + if (!empty) { + return 'error properties: ' + j$.pp(result) + '\n'; + } + + return ''; + } } return ExceptionFormatter;