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