当前位置: 首页>>代码示例>>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;未经允许,请勿转载。