feat(exception_handler): print originalException and originalStack for all exceptions
This commit is contained in:
@ -132,7 +132,7 @@ export function main() {
|
||||
Injector.resolveAndCreate([Pipes.extend({'async': [secondPipeFactory]})]);
|
||||
|
||||
expect(() => injector.get(Pipes))
|
||||
.toThrowError(/Cannot extend Pipes without a parent injector/g);
|
||||
.toThrowErrorWith("Cannot extend Pipes without a parent injector");
|
||||
});
|
||||
|
||||
it('should extend di-inherited pipes', () => {
|
||||
|
@ -18,6 +18,7 @@ import {DOM} from 'angular2/src/dom/dom_adapter';
|
||||
import {PromiseWrapper} from 'angular2/src/facade/async';
|
||||
import {bind, Inject, Injector} from 'angular2/di';
|
||||
import {LifeCycle} from 'angular2/src/core/life_cycle/life_cycle';
|
||||
import {ExceptionHandler} from 'angular2/src/core/exception_handler';
|
||||
import {Testability, TestabilityRegistry} from 'angular2/src/core/testability/testability';
|
||||
import {DOCUMENT_TOKEN} from 'angular2/src/render/dom/dom_renderer';
|
||||
|
||||
@ -65,6 +66,12 @@ class HelloRootMissingTemplate {
|
||||
class HelloRootDirectiveIsNotCmp {
|
||||
}
|
||||
|
||||
class _NilLogger {
|
||||
log(s: any): void {}
|
||||
logGroup(s: any): void {}
|
||||
logGroupEnd(){};
|
||||
}
|
||||
|
||||
export function main() {
|
||||
var fakeDoc, el, el2, testBindings, lightDom;
|
||||
|
||||
@ -85,17 +92,19 @@ export function main() {
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
var refPromise = bootstrap(HelloRootDirectiveIsNotCmp, testBindings);
|
||||
|
||||
PromiseWrapper.then(refPromise, null, (reason) => {
|
||||
expect(reason.message)
|
||||
.toContain(
|
||||
`Could not load '${stringify(HelloRootDirectiveIsNotCmp)}' because it is not a component.`);
|
||||
PromiseWrapper.then(refPromise, null, (exception) => {
|
||||
expect(exception).toContainError(
|
||||
`Could not load '${stringify(HelloRootDirectiveIsNotCmp)}' because it is not a component.`);
|
||||
async.done();
|
||||
return null;
|
||||
});
|
||||
}));
|
||||
|
||||
it('should throw if no element is found', inject([AsyncTestCompleter], (async) => {
|
||||
var refPromise = bootstrap(HelloRootCmp, []);
|
||||
// do not print errors to the console
|
||||
var e = new ExceptionHandler(new _NilLogger());
|
||||
|
||||
var refPromise = bootstrap(HelloRootCmp, [bind(ExceptionHandler).toValue(e)]);
|
||||
PromiseWrapper.then(refPromise, null, (reason) => {
|
||||
expect(reason.message).toContain('The selector "hello-app" did not match any elements');
|
||||
async.done();
|
||||
|
@ -67,8 +67,8 @@ main() {
|
||||
directives: [ThrowingComponent]))
|
||||
|
||||
.createAsync(Dummy).catchError((e, stack) {
|
||||
expect(e.message).toContain("MockException");
|
||||
expect(e.message).toContain("functionThatThrows");
|
||||
expect(e).toContainError("MockException");
|
||||
expect(e).toContainError("functionThatThrows");
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
@ -82,8 +82,8 @@ main() {
|
||||
directives: [ThrowingComponent2]))
|
||||
|
||||
.createAsync(Dummy).catchError((e, stack) {
|
||||
expect(e.message).toContain("NonError");
|
||||
expect(e.message).toContain("functionThatThrows");
|
||||
expect(e).toContainError("NonError");
|
||||
expect(e).toContainError("functionThatThrows");
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
@ -17,74 +17,78 @@ import {ExceptionHandler} from 'angular2/src/core/exception_handler';
|
||||
|
||||
class _CustomException {
|
||||
context = "some context";
|
||||
toString(): string { return "custom"; }
|
||||
}
|
||||
|
||||
export function main() {
|
||||
describe('ExceptionHandler', () => {
|
||||
var log, handler;
|
||||
|
||||
beforeEach(() => {
|
||||
log = new Log();
|
||||
handler = new ExceptionHandler();
|
||||
handler.logError = (e) => log.add(e);
|
||||
});
|
||||
|
||||
it("should output exception", () => {
|
||||
try {
|
||||
handler.call(new BaseException("message!"));
|
||||
} catch (e) {
|
||||
}
|
||||
expect(log.result()).toContain("message!");
|
||||
var e = ExceptionHandler.exceptionToString(new BaseException("message!"));
|
||||
expect(e).toContain("message!");
|
||||
});
|
||||
|
||||
it("should output stackTrace", () => {
|
||||
try {
|
||||
handler.call(new BaseException("message!"), "stack!");
|
||||
} catch (e) {
|
||||
}
|
||||
expect(log.result()).toContain("stack!");
|
||||
var e = ExceptionHandler.exceptionToString(new BaseException("message!"), "stack!");
|
||||
expect(e).toContain("stack!");
|
||||
});
|
||||
|
||||
it("should join a long stackTrace", () => {
|
||||
try {
|
||||
handler.call(new BaseException("message!"), ["stack1", "stack2"]);
|
||||
} catch (e) {
|
||||
}
|
||||
expect(log.result()).toContain("stack1");
|
||||
expect(log.result()).toContain("stack2");
|
||||
var e =
|
||||
ExceptionHandler.exceptionToString(new BaseException("message!"), ["stack1", "stack2"]);
|
||||
expect(e).toContain("stack1");
|
||||
expect(e).toContain("stack2");
|
||||
});
|
||||
|
||||
it("should output reason when present", () => {
|
||||
try {
|
||||
handler.call(new BaseException("message!"), null, "reason!");
|
||||
} catch (e) {
|
||||
}
|
||||
expect(log.result()).toContain("reason!");
|
||||
var e = ExceptionHandler.exceptionToString(new BaseException("message!"), null, "reason!");
|
||||
expect(e).toContain("reason!");
|
||||
});
|
||||
|
||||
it("should print context", () => {
|
||||
try {
|
||||
handler.call(new BaseException("message!", null, null, "context!"));
|
||||
} catch (e) {
|
||||
}
|
||||
expect(log.result()).toContain("context!");
|
||||
});
|
||||
describe("context", () => {
|
||||
it("should print context", () => {
|
||||
var e = ExceptionHandler.exceptionToString(
|
||||
new BaseException("message!", null, null, "context!"));
|
||||
expect(e).toContain("context!");
|
||||
});
|
||||
|
||||
it("should print nested context", () => {
|
||||
try {
|
||||
it("should print nested context", () => {
|
||||
var original = new BaseException("message!", null, null, "context!");
|
||||
handler.call(new BaseException("message", original));
|
||||
} catch (e) {
|
||||
}
|
||||
expect(log.result()).toContain("context!");
|
||||
var e = ExceptionHandler.exceptionToString(new BaseException("message", original));
|
||||
expect(e).toContain("context!");
|
||||
});
|
||||
|
||||
it("should not print context when the passed-in exception is not a BaseException", () => {
|
||||
var e = ExceptionHandler.exceptionToString(new _CustomException());
|
||||
expect(e).not.toContain("context");
|
||||
});
|
||||
});
|
||||
|
||||
it("should not print context when the passed-in exception is not a BaseException", () => {
|
||||
try {
|
||||
handler.call(new _CustomException());
|
||||
} catch (e) {
|
||||
}
|
||||
expect(log.result()).not.toContain("context");
|
||||
describe('original exception', () => {
|
||||
it("should print original exception message if available (original is BaseException)", () => {
|
||||
var realOriginal = new BaseException("inner");
|
||||
var original = new BaseException("wrapped", realOriginal);
|
||||
var e = ExceptionHandler.exceptionToString(new BaseException("wrappedwrapped", original));
|
||||
expect(e).toContain("inner");
|
||||
});
|
||||
|
||||
it("should print original exception message if available (original is not BaseException)",
|
||||
() => {
|
||||
var realOriginal = new _CustomException();
|
||||
var original = new BaseException("wrapped", realOriginal);
|
||||
var e =
|
||||
ExceptionHandler.exceptionToString(new BaseException("wrappedwrapped", original));
|
||||
expect(e).toContain("custom");
|
||||
});
|
||||
});
|
||||
|
||||
describe('original stack', () => {
|
||||
it("should print original stack if available", () => {
|
||||
var realOriginal = new BaseException("inner");
|
||||
var original = new BaseException("wrapped", realOriginal, "originalStack");
|
||||
var e = ExceptionHandler.exceptionToString(
|
||||
new BaseException("wrappedwrapped", original, "wrappedStack"));
|
||||
expect(e).toContain("originalStack");
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
@ -74,7 +74,7 @@ export function main() {
|
||||
var router = rootTC.componentInstance.router;
|
||||
PromiseWrapper.catchError(router.navigate('/cause-error'), (error) => {
|
||||
expect(rootTC.nativeElement).toHaveText('outer { oh no }');
|
||||
expect(error.message).toContain('oops!');
|
||||
expect(error).toContainError('oops!');
|
||||
async.done();
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user