0

尝试测试成对使用的方法。

方法:


this.x$.pipe(pairwise()).subscribe((x) => {
      const [previous, current] = x;
      this.store.dispatch(actionThatIWantToFire({ appId: current }));
    });

用于演示目的。我知道我不需要成对的。假装我愿意。

测试:

it(
    `should dispatch`,
    waitForAsync(() => {
      const dispatchSpy = jest.spyOn(store, 'dispatch');
      (component.x$ as Observable<any>) = cold('a---b|', {
        a: '123',
        b: '1234',
      });

      getTestScheduler().flush();
      expect(dispatchSpy).toHaveBeenCalledWith(
       actionThatIWantToFire,
      );
    }),
  );

但是订阅中的代码永远不会被调用。调用它的唯一方法是删除pairwise. 有任何想法吗?

4

0 回答 0