How do I test a function that returns an observable using timed intervals in rxjs 5?

后端 未结 4 1932
感情败类
感情败类 2020-12-03 18:33

For example, I have a function like this:

export function timeRange(start: number, end: number): Rx.Observable {
  return Rx.Observable.interva         


        
4条回答
  •  误落风尘
    2020-12-03 19:02

    You create either a TestScheduler or VirtualTimeScheduler and pass it as the optional second argument to Observable.Interval. In your case you'd simply add an optional scheduler argument to timeRange and pass the value on.

    These test schedulers allow you to "pass time" without waiting for actual time to elapse.

    For more information and examples, see Testing your Rx Application

提交回复
热议问题