feat(errors): preserve stack traces of user exceptions in Dart
This commit is contained in:
@ -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();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user