feat(errors): preserve stack traces of user exceptions in Dart

This commit is contained in:
Yegor Jbanov
2015-05-15 11:46:34 -07:00
parent 421d8916a6
commit b6f29b4448
3 changed files with 146 additions and 2 deletions

View File

@ -6,6 +6,19 @@ import 'package:angular2/di.dart';
import 'package:angular2/src/test_lib/test_bed.dart';
import 'package:angular2/test_lib.dart';
class MockException implements Error { var message; var stackTrace; }
void functionThatThrows() {
try { throw new MockException(); }
catch(e, stack) {
// If we lose the stack trace the message will no longer match
// the first line in the stack
e.message = stack.toString().split('\n')[0];
e.stackTrace = stack;
rethrow;
}
}
main() {
describe('TypeLiteral', () {
it('should publish via injectables',
@ -22,6 +35,21 @@ main() {
});
}));
});
describe('Error handling', () {
it('should preserve stack traces throws from components',
inject([TestBed, AsyncTestCompleter], (tb, async) {
tb.overrideView(Dummy, new View(
template: '<throwing-component></throwing-component>',
directives: [ThrowingComponent]
));
tb.createView(Dummy).catchError((e, stack) {
expect(stack.toString().split('\n')[0]).toEqual(e.message);
async.done();
});
}));
});
}
@Component(selector: 'dummy')
@ -43,3 +71,13 @@ class TypeLiteralComponent {
TypeLiteralComponent(this.list);
}
@Component(
selector: 'throwing-component'
)
@View(template: '')
class ThrowingComponent {
ThrowingComponent() {
functionThatThrows();
}
}