diff --git a/spec/core/ExceptionFormatterSpec.js b/spec/core/ExceptionFormatterSpec.js index 97f2c254..54deab8f 100644 --- a/spec/core/ExceptionFormatterSpec.js +++ b/spec/core/ExceptionFormatterSpec.js @@ -197,7 +197,7 @@ describe('ExceptionFormatter', function() { expect(new jasmineUnderTest.ExceptionFormatter().stack()).toBeNull(); }); - it('includes error properties in stack', function() { + it("includes the error's own properties in stack", function() { const error = new Error('an error'); error.someProperty = 'hello there'; @@ -206,6 +206,19 @@ describe('ExceptionFormatter', function() { expect(result).toMatch(/error properties:.*someProperty.*hello there/); }); + it('does not include inherited error properties', function() { + function CustomError(msg) { + Error.call(this, msg); + } + + CustomError.prototype = new Error(); + CustomError.prototype.anInheritedProp = 'something'; + const error = new CustomError('nope'); + + const result = new jasmineUnderTest.ExceptionFormatter().stack(error); + expect(result).not.toContain('anInheritedProp'); + }); + describe('When omitMessage is true', function() { it('filters the message from V8-style stack traces', function() { const error = { diff --git a/src/core/ExceptionFormatter.js b/src/core/ExceptionFormatter.js index 1b78de0f..c2d6710a 100644 --- a/src/core/ExceptionFormatter.js +++ b/src/core/ExceptionFormatter.js @@ -102,7 +102,7 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) { const result = {}; let empty = true; - for (const prop in error) { + for (const prop of Object.keys(error)) { if (ignoredProperties.includes(prop)) { continue; }