2016-06-23 12:47:54 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
import {beforeEach, ddescribe, describe, expect, iit, inject, it, xdescribe, xit,} from '@angular/core/testing/testing_internal';
|
2016-04-28 20:50:03 -04:00
|
|
|
import {BaseException, WrappedException, ExceptionHandler} from '../src/exceptions';
|
2015-07-22 20:13:42 -04:00
|
|
|
|
|
|
|
class _CustomException {
|
2016-06-08 19:38:52 -04:00
|
|
|
context = 'some context';
|
|
|
|
toString(): string { return 'custom'; }
|
2015-07-22 20:13:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export function main() {
|
|
|
|
describe('ExceptionHandler', () => {
|
2016-06-08 19:38:52 -04:00
|
|
|
it('should output exception', () => {
|
|
|
|
var e = ExceptionHandler.exceptionToString(new BaseException('message!'));
|
|
|
|
expect(e).toContain('message!');
|
2015-07-22 20:13:42 -04:00
|
|
|
});
|
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
it('should output stackTrace', () => {
|
|
|
|
var e = ExceptionHandler.exceptionToString(new BaseException('message!'), 'stack!');
|
|
|
|
expect(e).toContain('stack!');
|
2015-07-22 20:13:42 -04:00
|
|
|
});
|
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
it('should join a long stackTrace', () => {
|
2015-07-23 21:00:19 -04:00
|
|
|
var e =
|
2016-06-08 19:38:52 -04:00
|
|
|
ExceptionHandler.exceptionToString(new BaseException('message!'), ['stack1', 'stack2']);
|
|
|
|
expect(e).toContain('stack1');
|
|
|
|
expect(e).toContain('stack2');
|
2015-07-22 20:13:42 -04:00
|
|
|
});
|
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
it('should output reason when present', () => {
|
|
|
|
var e = ExceptionHandler.exceptionToString(new BaseException('message!'), null, 'reason!');
|
|
|
|
expect(e).toContain('reason!');
|
2015-07-22 20:13:42 -04:00
|
|
|
});
|
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
describe('context', () => {
|
|
|
|
it('should print context', () => {
|
2015-07-23 21:00:19 -04:00
|
|
|
var e = ExceptionHandler.exceptionToString(
|
2016-06-08 19:38:52 -04:00
|
|
|
new WrappedException('message!', null, null, 'context!'));
|
|
|
|
expect(e).toContain('context!');
|
2015-07-23 21:00:19 -04:00
|
|
|
});
|
2015-07-22 20:13:42 -04:00
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
it('should print nested context', () => {
|
|
|
|
var original = new WrappedException('message!', null, null, 'context!');
|
|
|
|
var e = ExceptionHandler.exceptionToString(new WrappedException('message', original));
|
|
|
|
expect(e).toContain('context!');
|
2015-07-23 21:00:19 -04:00
|
|
|
});
|
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
it('should not print context when the passed-in exception is not a BaseException', () => {
|
2015-07-23 21:00:19 -04:00
|
|
|
var e = ExceptionHandler.exceptionToString(new _CustomException());
|
2016-06-08 19:38:52 -04:00
|
|
|
expect(e).not.toContain('context');
|
2015-07-23 21:00:19 -04:00
|
|
|
});
|
2015-07-22 20:13:42 -04:00
|
|
|
});
|
|
|
|
|
2015-07-23 21:00:19 -04:00
|
|
|
describe('original exception', () => {
|
2016-06-08 19:38:52 -04:00
|
|
|
it('should print original exception message if available (original is BaseException)', () => {
|
|
|
|
var realOriginal = new BaseException('inner');
|
|
|
|
var original = new WrappedException('wrapped', realOriginal);
|
2015-09-10 18:25:36 -04:00
|
|
|
var e =
|
2016-06-08 19:38:52 -04:00
|
|
|
ExceptionHandler.exceptionToString(new WrappedException('wrappedwrapped', original));
|
|
|
|
expect(e).toContain('inner');
|
2015-07-23 21:00:19 -04:00
|
|
|
});
|
|
|
|
|
2016-06-08 19:38:52 -04:00
|
|
|
it('should print original exception message if available (original is not BaseException)',
|
2015-07-23 21:00:19 -04:00
|
|
|
() => {
|
|
|
|
var realOriginal = new _CustomException();
|
2016-06-08 19:38:52 -04:00
|
|
|
var original = new WrappedException('wrapped', realOriginal);
|
2015-07-23 21:00:19 -04:00
|
|
|
var e =
|
2016-06-08 19:38:52 -04:00
|
|
|
ExceptionHandler.exceptionToString(new WrappedException('wrappedwrapped', original));
|
|
|
|
expect(e).toContain('custom');
|
2015-07-23 21:00:19 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('original stack', () => {
|
2016-06-08 19:38:52 -04:00
|
|
|
it('should print original stack if available', () => {
|
|
|
|
var realOriginal = new BaseException('inner');
|
|
|
|
var original = new WrappedException('wrapped', realOriginal, 'originalStack');
|
2015-07-23 21:00:19 -04:00
|
|
|
var e = ExceptionHandler.exceptionToString(
|
2016-06-08 19:38:52 -04:00
|
|
|
new WrappedException('wrappedwrapped', original, 'wrappedStack'));
|
|
|
|
expect(e).toContain('originalStack');
|
2015-07-23 21:00:19 -04:00
|
|
|
});
|
2015-07-22 20:13:42 -04:00
|
|
|
});
|
|
|
|
});
|
2015-08-11 17:00:54 -04:00
|
|
|
}
|