本文整理匯總了TypeScript中app/services.HttpErrorHandler類的典型用法代碼示例。如果您正苦於以下問題:TypeScript HttpErrorHandler類的具體用法?TypeScript HttpErrorHandler怎麽用?TypeScript HttpErrorHandler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了HttpErrorHandler類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: describe
describe('ErrorHandler', () => {
var errorHandler:HttpErrorHandler;
var loginService:LoginService;
var router:Router;
beforeEachProviders(() => [
APP_TEST_PROVIDERS,
provide(ROUTER_PRIMARY_COMPONENT, {useValue: App}),
]);
beforeEach(inject([HttpErrorHandler, LoginService, Router], (..._) => {
[errorHandler, loginService, router] = _;
spyOn(loginService, 'logout');
spyOn(router, 'navigate');
}));
describe('.handle', () => {
it('handles 401 response', () => {
errorHandler.handle({status: 401});
expect(loginService.logout).toHaveBeenCalled();
expect(router.navigate).toHaveBeenCalledWith(['/Login']);
});
it('does not handle other errors', () => {
errorHandler.handle({status: 400});
expect(loginService.logout).not.toHaveBeenCalled();
expect(router.navigate).not.toHaveBeenCalled();
});
}); // .handle
});
示例3: it
it('does not handle other errors', () => {
errorHandler.handle({status: 400});
expect(loginService.logout).not.toHaveBeenCalled();
expect(router.navigate).not.toHaveBeenCalled();
});