本文整理匯總了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);
}