Как создать наблюдаемый тест таймера в жасминовом мраморе? - PullRequest
0 голосов
/ 12 сентября 2018

Я не могу создать тест для проверки таймера, наблюдаемого в функции startTimer.Я использую 6.3.1 версию RXJS.

Это мой код:

private createSubscribe(): void {
  if (this.timer) {
    this.subscription = this.timer.subscribe(() => {
      this.cream().then(() => {
        this.subscription.unsubscribe();
        this.subscription = null;
        this.timer = null;
        this.startTimer(this.config.period);
      });
    });
  }
}

private startTimer(period): void {
  if (period) {
    this.timer = timer(period * 1000);
    this.createSubscribe();
  }
}

1 Ответ

0 голосов
/ 13 сентября 2018

Я решаю свою проблему, используя:

it('startTimer: should call createSubscribe and set timer with observable emited in 5000ms.', () => {

  const scheduler = new TestScheduler((actual, expected) => {
    expect(actual).toEqual(expected);
  });

  scheduler.run(helpers => {
    const { expectObservable } = helpers;
    const period = 5;
    const expected = '5000ms (a|)';
    spyOn(helper, <any>'createSubscribe');

    helper['startTimer'](period);

    expectObservable(helper['timer']).toBe(expected, {a : 0});
    expect(helper['createSubscribe']).toHaveBeenCalled();
  });
});
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...