1

This question is about RxJS5.

Context: I tried using TestScheduler, it all works fine until I plug in the promises.

For instance let's take "someFunction" from the example below. How would I validate the output expected within 1 minute period (without actually having to wait 1 minute in the test).

const asyncFunction = new Promise( (resolve) =>
   setTimeout((() => resolve(1)), 0)
);

const someFunction = () =>
  Rx.Observable.fromInterval(15000)
    .flatMap( each => Rx.Observable.from(asyncFunction()))
    .map(each => each + 1)
Paweł Badeński
  • 399
  • 3
  • 12

1 Answers1

0

I think this answer sums up basically everything you need to know: How do I test a function that returns an observable using timed intervals in rxjs 5?

Simply said, you should allow the user to set custom delay even thought the default value can be 15000:

const someFunction = (delay = 15000) =>
  Rx.Observable.fromInterval(delay)
  ...

Then for the TestSheduler you need to use delay <= 750 because 750 is hardcoded as the maximum virtual time. See the answer linked above for more details.

Community
  • 1
  • 1
martin
  • 93,354
  • 25
  • 191
  • 226
  • Thanks, this is useful piece of information, since I did have problems with longer delays! However linked answer doesn't mention promises and in my situation, even with low delays, tests do not work with observables based on promises. – Paweł Badeński Mar 22 '17 at 13:56