0

I assume that when testing code with Promises it is required to use fakeAsync/tick combination to guarantee that promises are resolves/rejects. This is because tick drains microtasks queue when invoked.

However, what about Observables? Should we also use fakeAsync/tick to guarantee that subscribe handler is invoked? Looks like unit tests with Observables are completed fine, with all the subscribed Observer instances notified, without fakeAsync/tick so I'm not sure if this is required or not.

Thank you

Alex Ryltsov
  • 2,385
  • 17
  • 25

1 Answers1

0

Late answer (You might have already figured this out by now). Although would like to mention it if anyone else is having the same doubt.

As explained in below answer, "each observable operator uses the minimum amount of asynchronicity needed to do its work".

Synchronicity in RxJS

So it depends primarily what RxJs Operator we use.

Let's say, we use a Subject/BehaviorSubject to push new values in the stream while we are running Unit tests (I believe this is one of the ways to mock an Observable based data store implementation), then we do not need to have fakeAsync and tick since subscribe handlers will get called synchronously.