cartant / rxjs-marbles

An RxJS marble testing library for any test framework
https://cartant.github.io/rxjs-marbles/
MIT License
300 stars 18 forks source link

RxJs BufferTime operator not supported to mock elapsed time #74

Closed BrunoBeraudPW closed 3 years ago

BrunoBeraudPW commented 3 years ago

Hello

I can't mock time elapsed when I use bufferTime operator with fakeSchedulers

I created this environment to demonstrate you the issue : https://stackblitz.com/edit/rxjs-marbles-buffer-time-issue?file=src%2Fbuffer-time.spec.ts

FakeSchedulers works well with delay / debounceTime, but not with bufferTime.

For now I can use a workaround in using buffer(source.pipe(debounceTime(timeInMs)) because I don't need the "interval" behavior of bufferTime

Do you have an idea ?

Thank you !

cartant commented 3 years ago

Do you have an idea ?

No, it seems very strange. Thanks for creating the reproduction. I don't have time to look at this, ATM; maybe on the weekend.

cartant commented 3 years ago

I'm closing this, 'cause, AFAICT, this behaviour has nothing to do with this package. Note that when EMPTY is used as the source, bufferTime is completely synchronous - as the source immediately emits a complete notification:

import { EMPTY } from "rxjs";
import { bufferTime } from "rxjs/operators";

EMPTY.pipe(bufferTime(1e3)).subscribe((value) => console.log(value));
console.log("subscribed");

which outputs:

[]
subscribed

Also, in the test, if you log sut.toggleBufferTime immediately before the expectation is performed, its value is true, so ... 🤷‍♂️, but this has nothing to do with rxjs-marbles, IMO.

BrunoBeraudPW commented 3 years ago

In deed, sorry to have wasted your time. The example was in fact not relevant, it's surely a trouble with my production code, I will dig in my side. Thank you for your time !