Exclude inherited Error properties from stack trace
These are likely to be methods or other things that aren't meaningful in Jasmine's output.
This commit is contained in:
@@ -197,7 +197,7 @@ describe('ExceptionFormatter', function() {
|
|||||||
expect(new jasmineUnderTest.ExceptionFormatter().stack()).toBeNull();
|
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');
|
const error = new Error('an error');
|
||||||
error.someProperty = 'hello there';
|
error.someProperty = 'hello there';
|
||||||
|
|
||||||
@@ -206,6 +206,19 @@ describe('ExceptionFormatter', function() {
|
|||||||
expect(result).toMatch(/error properties:.*someProperty.*hello there/);
|
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() {
|
describe('When omitMessage is true', function() {
|
||||||
it('filters the message from V8-style stack traces', function() {
|
it('filters the message from V8-style stack traces', function() {
|
||||||
const error = {
|
const error = {
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
|
|||||||
const result = {};
|
const result = {};
|
||||||
let empty = true;
|
let empty = true;
|
||||||
|
|
||||||
for (const prop in error) {
|
for (const prop of Object.keys(error)) {
|
||||||
if (ignoredProperties.includes(prop)) {
|
if (ignoredProperties.includes(prop)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user