2016-04-07 20:17:50 -04:00
|
|
|
import {AsyncTestCompleter, beforeEach, ddescribe, describe, expect, iit, inject, it, xdescribe, xit, Log} from 'angular2/testing_internal';
|
2015-11-06 20:34:07 -05:00
|
|
|
import {BaseException, WrappedException, ExceptionHandler} from 'angular2/src/facade/exceptions';
|
2015-07-22 20:13:42 -04:00
|
|
|
|
|
|
|
class _CustomException {
|
2016-04-07 20:17:50 -04:00
|
|
|
context = 'some context';
|
|
|
|
toString(): string { return 'custom'; }
|
2015-07-22 20:13:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export function main() {
|
|
|
|
describe('ExceptionHandler', () => {
|
2016-04-07 20:17:50 -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-04-07 20:17:50 -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-04-07 20:17:50 -04:00
|
|
|
it('should join a long stackTrace', () => {
|
2015-07-23 21:00:19 -04:00
|
|
|
var e =
|
2016-04-07 20:17:50 -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-04-07 20:17:50 -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-04-07 20:17:50 -04:00
|
|
|
describe('context', () => {
|
|
|
|
it('should print context', () => {
|
2015-07-23 21:00:19 -04:00
|
|
|
var e = ExceptionHandler.exceptionToString(
|
2016-04-07 20:17:50 -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-04-07 20:17:50 -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-04-07 20:17:50 -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-04-07 20:17:50 -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-04-07 20:17:50 -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-04-07 20:17:50 -04:00
|
|
|
ExceptionHandler.exceptionToString(new WrappedException('wrappedwrapped', original));
|
|
|
|
expect(e).toContain('inner');
|
2015-07-23 21:00:19 -04:00
|
|
|
});
|
|
|
|
|
2016-04-07 20:17:50 -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-04-07 20:17:50 -04:00
|
|
|
var original = new WrappedException('wrapped', realOriginal);
|
2015-07-23 21:00:19 -04:00
|
|
|
var e =
|
2016-04-07 20:17:50 -04:00
|
|
|
ExceptionHandler.exceptionToString(new WrappedException('wrappedwrapped', original));
|
|
|
|
expect(e).toContain('custom');
|
2015-07-23 21:00:19 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('original stack', () => {
|
2016-04-07 20:17:50 -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-04-07 20:17:50 -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
|
|
|
}
|