Skip to content

Commit

Permalink
Exclude inherited Error properties from stack trace
Browse files Browse the repository at this point in the history
These are likely to be methods or other things that aren't meaningful in
Jasmine's output.
  • Loading branch information
sgravrock committed Jul 20, 2023
1 parent 59d1c5b commit 75d45ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion spec/core/ExceptionFormatterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion src/core/ExceptionFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 75d45ef

Please sign in to comment.