fix(errors): require passing stack traces explicitly in ng2 own code

This commit is contained in:
Yegor Jbanov
2015-05-19 12:48:00 -07:00
parent 5c88f662cd
commit 8ab773538b
11 changed files with 112 additions and 75 deletions

View File

@ -7,6 +7,7 @@ import 'package:angular2/src/test_lib/test_bed.dart';
import 'package:angular2/test_lib.dart';
class MockException implements Error { var message; var stackTrace; }
class NonError { var message; }
void functionThatThrows() {
try { throw new MockException(); }
@ -19,6 +20,16 @@ void functionThatThrows() {
}
}
void functionThatThrowsNonError() {
try { throw new NonError(); }
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];
rethrow;
}
}
main() {
describe('TypeLiteral', () {
it('should publish via appInjector',
@ -37,7 +48,7 @@ main() {
});
describe('Error handling', () {
it('should preserve stack traces throws from components',
it('should preserve Error stack traces thrown from components',
inject([TestBed, AsyncTestCompleter], (tb, async) {
tb.overrideView(Dummy, new View(
template: '<throwing-component></throwing-component>',
@ -49,6 +60,19 @@ main() {
async.done();
});
}));
it('should preserve non-Error stack traces thrown from components',
inject([TestBed, AsyncTestCompleter], (tb, async) {
tb.overrideView(Dummy, new View(
template: '<throwing-component2></throwing-component2>',
directives: [ThrowingComponent2]
));
tb.createView(Dummy).catchError((e, stack) {
expect(stack.toString().split('\n')[0]).toEqual(e.message);
async.done();
});
}));
});
}
@ -81,3 +105,13 @@ class ThrowingComponent {
functionThatThrows();
}
}
@Component(
selector: 'throwing-component2'
)
@View(template: '')
class ThrowingComponent2 {
ThrowingComponent2() {
functionThatThrowsNonError();
}
}