當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Subject.error方法代碼示例

本文整理匯總了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"));
 });
開發者ID:nteract,項目名稱:nteract,代碼行數:7,代碼來源:message-subject-spec.ts

示例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.`);
  });
開發者ID:Ninja-Squad,項目名稱:globe42,代碼行數:26,代碼來源:login.component.spec.ts

示例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"));
  });
開發者ID:canalplus,項目名稱:rx-player,代碼行數:58,代碼來源:cast_to_observable.test.ts

示例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);
});
開發者ID:milutinovici,項目名稱:proactive,代碼行數:9,代碼來源:state-spec.ts

示例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);
  });
開發者ID:canalplus,項目名稱:rx-player,代碼行數:43,代碼來源:rx-throttle.test.ts

示例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
        });
    });
開發者ID:chevtche,項目名稱:Brayns,代碼行數:15,代碼來源:request.spec.ts

示例7:

 error => observer.error(error));
開發者ID:slamdunking,項目名稱:search-maven-org,代碼行數:1,代碼來源:search.service.ts

示例8: failExecution

 failExecution(err): void {
   this._subject.error(err);
 }
開發者ID:Kineolyan,項目名稱:Jarvis,代碼行數:3,代碼來源:ProgramExecutor.ts

示例9:

 error => {
   resultSubject.error(error);
 }
開發者ID:wzong,項目名稱:TinyCloud,代碼行數:3,代碼來源:streaming.ts


注:本文中的rxjs.Subject.error方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。