本文整理汇总了TypeScript中rxjs.Subject.error方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Subject.error方法的具体用法?TypeScript Subject.error怎么用?TypeScript Subject.error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rxjs.Subject
的用法示例。
在下文中一共展示了Subject.error方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it("communicates failure", async () => {
const errorPromise = new Promise<string>(resolve => {
messageSubject2.subscribe({ error: resolve });
});
messageSubject1.error("error text");
expect(await errorPromise).toEqual(new Error("error text"));
});
示例2: it
it('should call the user service and display a message if failed', () => {
const currentUserService: CurrentUserService = TestBed.get(CurrentUserService);
const router: Router = TestBed.get(Router);
const subject = new Subject<UserModel>();
spyOn(currentUserService, 'authenticate').and.returnValue(subject);
spyOn(router, 'navigate');
tester.login.fillWith('login');
tester.password.fillWith('password');
tester.submit.click();
// then we should have called the user service method
expect(currentUserService.authenticate).toHaveBeenCalledWith({
login: 'login',
password: 'password'
});
subject.error(new Error());
tester.detectChanges();
// and not redirect to the home
expect(router.navigate).not.toHaveBeenCalled();
expect(tester.testElement).toContainText(`Erreur d'authentification, essayez encore.`);
});
示例3: it
it("should translate Observable implementation not from RxJS into RxJS Observables", (done) => {
/* tslint:enable:max-line-length */
const sub1 = new Subject<number>();
const sub2 = new Subject<number>();
const myObs1 = {
subscribe(a : () => void, b : () => void, c : () => {}) {
sub1.subscribe(a, b, c);
return null;
},
};
const myObs2 = {
subscribe(a : () => void, b : () => void, c : () => {}) {
sub2.subscribe(a, b, c);
return null;
},
};
const rxObs1 = castToObservable(myObs1);
const rxObs2 = castToObservable(myObs2);
let itemFromObs1 = 0;
let itemFromObs2 = 0;
rxObs1.subscribe(
(num) => {
switch (itemFromObs1++) {
case 0:
expect(num).toBe(1);
break;
case 1:
expect(num).toBe(12);
break;
case 2:
expect(num).toBe(5);
break;
default:
throw new Error("Invalid item received");
}
},
(err : Error) => {
expect(err.message).toBe("ffob");
expect(itemFromObs1).toBe(3);
rxObs2.subscribe(
() => { itemFromObs2++; },
noop,
() => {
expect(itemFromObs2).toBe(0);
done();
}
);
}
);
sub1.next(1);
sub1.next(12);
sub1.next(5);
sub2.complete();
sub1.error(new Error("ffob"));
});
示例4: it
it("allows connecting an error handler at construction", async t => {
const subject = new Subject<number>();
let errorCount = 0;
subject.toState(0).subscribe(() => {}, () => errorCount++);
subject.error("error");
t.is(errorCount, 1);
});
示例5: it
it("should execute Observable coming after the previous one has errored", (done) => {
const sub1 = new Subject<void>();
const sub2 = new Subject<void>();
const sub3 = new Subject<void>();
const obsFunction = (sub : Subject<void>) : Observable<void> => {
return concat(observableOf(undefined), sub);
};
const throttledObsFunction = throttle(obsFunction);
const Obs1 = throttledObsFunction(sub1);
const Obs2 = throttledObsFunction(sub2);
const Obs3 = throttledObsFunction(sub3);
const error = new Error("ffo");
let itemsReceivedFrom1 = 0;
let itemsReceivedFrom3 = 0;
let has1Errored = false;
Obs2.subscribe();
sub2.complete();
Obs1.subscribe(
() => { itemsReceivedFrom1++; },
(e) => {
expect(e).toBe("titi");
has1Errored = true;
}
);
sub1.error("titi");
Obs3.subscribe(
() => { itemsReceivedFrom3++; },
(e) => {
expect(e).toBe(error);
expect(has1Errored).toBe(true);
expect(itemsReceivedFrom1).toBe(1);
expect(itemsReceivedFrom3).toBe(1);
done();
}
);
sub3.error(error);
});
示例6: it
it('dispatches a request complete event with the request when the request throws', () => {
const source = new Subject();
const request = new Request('test');
const error = new Error('Oops :(');
const task = createTask(source, request);
dispatchRequest(task);
source.error(error);
expect(mockDispatchEvent).toHaveBeenCalledWith(REQUEST_DONE, {
request,
error
});
});
示例7:
error => observer.error(error));
示例8: failExecution
failExecution(err): void {
this._subject.error(err);
}