test(core): update ErrorHandler tests to handle browsers without stack (#11141)

Fixes #11114
This commit is contained in:
Marc Laval 2016-08-29 17:17:45 +02:00 committed by Victor Berchet
parent af63378fa0
commit 7dee1ee4cf
1 changed files with 16 additions and 8 deletions

View File

@ -48,8 +48,10 @@ export function main() {
it('should output stackTrace', () => { it('should output stackTrace', () => {
var error = new Error('message!'); var error = new Error('message!');
var stack = getStack(error); var stack = getStack(error);
var e = errorToString(error); if (stack) {
expect(e).toContain(stack); var e = errorToString(error);
expect(e).toContain(stack);
}
}); });
describe('context', () => { describe('context', () => {
@ -62,11 +64,16 @@ export function main() {
} as any as DebugContext; } as any as DebugContext;
var original = new ViewWrappedError(cause, context); var original = new ViewWrappedError(cause, context);
var e = errorToString(new WrappedError('message', original)); var e = errorToString(new WrappedError('message', original));
expect(e).toEqual(`EXCEPTION: message caused by: Error in context! caused by: message! expect(e).toEqual(
stack ? `EXCEPTION: message caused by: Error in context! caused by: message!
ORIGINAL EXCEPTION: message! ORIGINAL EXCEPTION: message!
ORIGINAL STACKTRACE: ORIGINAL STACKTRACE:
${stack} ${stack}
ERROR CONTEXT: ERROR CONTEXT:
Context` :
`EXCEPTION: message caused by: Error in context! caused by: message!
ORIGINAL EXCEPTION: message!
ERROR CONTEXT:
Context`); Context`);
}); });
}); });
@ -74,10 +81,9 @@ Context`);
describe('original exception', () => { describe('original exception', () => {
it('should print original exception message if available (original is Error)', () => { it('should print original exception message if available (original is Error)', () => {
var realOriginal = new Error('inner'); var realOriginal = new Error('inner');
var stack = getStack(realOriginal);
var original = new WrappedError('wrapped', realOriginal); var original = new WrappedError('wrapped', realOriginal);
var e = errorToString(new WrappedError('wrappedwrapped', original)); var e = errorToString(new WrappedError('wrappedwrapped', original));
expect(e).toContain(stack); expect(e).toContain('inner');
}); });
it('should print original exception message if available (original is not Error)', () => { it('should print original exception message if available (original is not Error)', () => {
@ -92,9 +98,11 @@ Context`);
it('should print original stack if available', () => { it('should print original stack if available', () => {
var realOriginal = new Error('inner'); var realOriginal = new Error('inner');
var stack = getStack(realOriginal); var stack = getStack(realOriginal);
var original = new WrappedError('wrapped', realOriginal); if (stack) {
var e = errorToString(new WrappedError('wrappedwrapped', original)); var original = new WrappedError('wrapped', realOriginal);
expect(e).toContain(stack); var e = errorToString(new WrappedError('wrappedwrapped', original));
expect(e).toContain(stack);
}
}); });
}); });
}); });