feat(exception_handler): print originalException and originalStack for all exceptions
This commit is contained in:
@ -119,7 +119,7 @@ function _getAppBindings() {
|
||||
DirectiveResolver,
|
||||
Parser,
|
||||
Lexer,
|
||||
ExceptionHandler,
|
||||
bind(ExceptionHandler).toValue(new ExceptionHandler(DOM)),
|
||||
bind(LocationStrategy).toClass(MockLocationStrategy),
|
||||
bind(XHR).toClass(MockXHR),
|
||||
ComponentUrlMapper,
|
||||
|
@ -22,6 +22,7 @@ import 'package:angular2/src/reflection/reflection_capabilities.dart';
|
||||
|
||||
import 'package:angular2/src/di/binding.dart' show bind;
|
||||
import 'package:angular2/src/di/injector.dart' show Injector;
|
||||
import 'package:angular2/src/core/exception_handler.dart' show ExceptionHandler;
|
||||
import 'package:angular2/src/facade/collection.dart' show StringMapWrapper;
|
||||
|
||||
import 'test_injector.dart';
|
||||
@ -77,13 +78,27 @@ Expect expect(actual, [matcher]) {
|
||||
|
||||
const _u = const Object();
|
||||
|
||||
expectErrorMessage(actual, expectedMessage) {
|
||||
expect(ExceptionHandler.exceptionToString(actual)).toContain(expectedMessage);
|
||||
}
|
||||
|
||||
expectException(Function actual, expectedMessage) {
|
||||
try {
|
||||
actual();
|
||||
} catch (e, s) {
|
||||
expectErrorMessage(e, expectedMessage);
|
||||
}
|
||||
}
|
||||
|
||||
class Expect extends gns.Expect {
|
||||
Expect(actual) : super(actual);
|
||||
|
||||
NotExpect get not => new NotExpect(actual);
|
||||
|
||||
void toEqual(expected) => toHaveSameProps(expected);
|
||||
void toContainError(message) => expectErrorMessage(this.actual, message);
|
||||
void toThrowError([message = ""]) => toThrowWith(message: message);
|
||||
void toThrowErrorWith(message) => expectException(this.actual, message);
|
||||
void toBePromise() => gns.guinness.matchers.toBeTrue(actual is Future);
|
||||
void toImplement(expected) => toBeA(expected);
|
||||
void toBeNaN() => gns.guinness.matchers.toBeTrue(double.NAN.compareTo(actual) == 0);
|
||||
|
@ -6,6 +6,7 @@ import {global} from 'angular2/src/facade/lang';
|
||||
import {NgZoneZone} from 'angular2/src/core/zone/ng_zone';
|
||||
|
||||
import {bind} from 'angular2/di';
|
||||
import {ExceptionHandler} from 'angular2/src/core/exception_handler';
|
||||
|
||||
import {createTestInjector, FunctionWithParamTokens, inject} from './test_injector';
|
||||
|
||||
@ -24,6 +25,8 @@ export interface NgMatchers extends jasmine.Matchers {
|
||||
toBeAnInstanceOf(expected: any): boolean;
|
||||
toHaveText(expected: any): boolean;
|
||||
toImplement(expected: any): boolean;
|
||||
toContainError(expected: any): boolean;
|
||||
toThrowErrorWith(expectedMessage: any): boolean;
|
||||
not: NgMatchers;
|
||||
}
|
||||
|
||||
@ -240,6 +243,38 @@ _global.beforeEach(function() {
|
||||
};
|
||||
},
|
||||
|
||||
toContainError: function() {
|
||||
return {
|
||||
compare: function(actual, expectedText) {
|
||||
var errorMessage = ExceptionHandler.exceptionToString(actual);
|
||||
return {
|
||||
pass: errorMessage.indexOf(expectedText) > -1,
|
||||
get message() { return 'Expected ' + errorMessage + ' to contain ' + expectedText; }
|
||||
};
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
toThrowErrorWith: function() {
|
||||
return {
|
||||
compare: function(actual, expectedText) {
|
||||
try {
|
||||
actual();
|
||||
return {
|
||||
pass: false,
|
||||
get message() { return "Was expected to throw, but did not throw"; }
|
||||
};
|
||||
} catch (e) {
|
||||
var errorMessage = ExceptionHandler.exceptionToString(e);
|
||||
return {
|
||||
pass: errorMessage.indexOf(expectedText) > -1,
|
||||
get message() { return 'Expected ' + errorMessage + ' to contain ' + expectedText; }
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
toImplement: function() {
|
||||
return {
|
||||
compare: function(actualObject, expectedInterface) {
|
||||
|
Reference in New Issue
Block a user