本文整理汇总了TypeScript中angular2/src/facade/async.PromiseWrapper.catchError方法的典型用法代码示例。如果您正苦于以下问题:TypeScript PromiseWrapper.catchError方法的具体用法?TypeScript PromiseWrapper.catchError怎么用?TypeScript PromiseWrapper.catchError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类angular2/src/facade/async.PromiseWrapper
的用法示例。
在下文中一共展示了PromiseWrapper.catchError方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: expect
tcb.createAsync(AppCmp).then((fixture) => {
var router = fixture.debugElement.componentInstance.router;
PromiseWrapper.catchError(router.navigateByUrl('/cause-error'), (error) => {
expect(error).toContainError('oops!');
async.done();
});
});
示例2: it
it('should reject the Promise on failure', inject([AsyncTestCompleter], (async) => {
PromiseWrapper.catchError(xhr.get(url404), (e) => {
expect(e).toEqual(`Failed to load ${url404}`);
async.done();
return null;
});
}));
示例3: navigate
/**
* Navigate to a URL. Returns a promise that resolves to the canonical URL for the route.
*
* If the given URL begins with a `/`, router will navigate absolutely.
* If the given URL does not begin with `/`, the router will navigate relative to this component.
*/
navigate(url: string): Promise<any> {
if (this.navigating) {
return PromiseWrapper.resolve(true);
}
this.lastNavigationAttempt = url;
var matchedInstruction = this.recognize(url);
if (isBlank(matchedInstruction)) {
return PromiseWrapper.resolve(false);
}
if (isPresent(this._currentInstruction)) {
matchedInstruction.reuseComponentsFrom(this._currentInstruction);
}
this._startNavigating();
var result = this.commit(matchedInstruction)
.then((_) => {
ObservableWrapper.callNext(this._subject, matchedInstruction.accumulatedUrl);
this._finishNavigating();
});
PromiseWrapper.catchError(result, (_) => this._finishNavigating());
return result;
}
示例4: inject
inject([AsyncTestCompleter], (async) => {
PromiseWrapper.catchError(aggregate([], {captureFrames: true}), (err) => {
expect(() => { throw err; })
.toThrowError(
'frame capture requested in benchpress, but no start event was found');
async.done();
});
}));
示例5: expect
.then((applicationRef) => {
var router = applicationRef.hostComponent.router;
PromiseWrapper.catchError(router.navigate('/cause-error'), (error) => {
expect(el).toHaveText('outer { oh no }');
expect(error.message).toBe('oops!');
async.done();
});
});
示例6: expect
tcb.createAsync(AppCmp).then((rootTC) => {
var router = rootTC.componentInstance.router;
PromiseWrapper.catchError(router.navigate('/cause-error'), (error) => {
expect(rootTC.nativeElement).toHaveText('outer { oh no }');
expect(error).toContainError('oops!');
async.done();
});
});
示例7: it
it('should throw for non components', inject([AsyncTestCompleter], (async) => {
PromiseWrapper.catchError(PromiseWrapper.wrap(() => compile([NonComponent])), (error) => {
expect(error.message)
.toEqual(
`Could not compile '${stringify(NonComponent)}' because it is not a component.`);
async.done();
});
}));
示例8: it
it('should throw if no end event', inject([AsyncTestCompleter], (async) => {
PromiseWrapper.catchError(
aggregate(
[eventFactory.markStart('frameCapture', 3), eventFactory.instant('frame', 4)],
{captureFrames: true}),
(err) => {
expect(() => { throw err; }).toThrowError('missing end event for frame capture');
async.done();
});
}));
示例9: it
it('should report loading errors', inject([AsyncTestCompleter], (async) => {
var compiler = createCompiler(EMPTY_STEP, MapWrapper.create());
PromiseWrapper.catchError(compiler.compile(new Template({
componentId: 'someId',
absUrl: 'someUrl'
})), (e) => {
expect(e.message).toContain(`Failed to load the template "someId"`);
async.done();
});
}));