Trying to test a method that is using pairwise.
Method:
this.x$.pipe(pairwise()).subscribe((x) => {
const [previous, current] = x;
this.store.dispatch(actionThatIWantToFire({ appId: current }));
});
For demonstration purposes. I'm aware that I don't need pairwise. Pretend that I do.
test:
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,
);
}),
);
But the code within the subscription never gets called. Only way to call it is to remove the pairwise
.
Any ideas?
From the RxJs Documentation :
I found a workaround using startwith before using pairwise :