fakeSchedulers stopped working with rxjs 7
thccorni opened this issue · comments
I recently upgraded rxjs and rxjs-marbles to v7 in a stencil project.
This caused some jest tests using fakeSchedulers
to test debounceTime
to stop working.
I don't know if this is a bug, or an error on my side, but any help would be really appreciated.
I created a repo that reproduces this https://github.com/thccorni/rxjs-marbles-fake-schedulers-with-rxjs-7
To summarize:
I have some component emitting user input after some debounce time.
this.countDebouncer$
.pipe(debounceTime(this.dueTime), takeUntil(this.destroy$))
.subscribe((count) => {
this.countChange.emit(count);
console.log('emitting', { count });
});
// some click handler
this.countDebouncer$.next(count)
I usually tested this using advance
with the appropriate amount of time, which worked great until now
fakeSchedulers(async (advance) => {
// omitted…
button.click();
expect(emit).not.toBeCalled();
advance(300);
expect(emit).toBeCalledTimes(1);
}),
Thanks for your help in advance!
fakeSchedulers
most likely won't work with an async
function because, AFAICT, as soon as the function returns - it'll return a promise - the scheduler patching/faking will be restored, so anything that happens with schedulers after an await
will be dealing with unpatched, no-longer-faked schedulers.
It could be made to work with an async
function, but ATM it won't and it never has in the past.
Thanks a lot for clarification. I could solve my problem by moving the async stuff before running fakeSchedulers
.