javascript - How do I get TestScheduler to tick in RxJs5? -
i'm trying write sample unit test observable.interval
in rxjs version 5. i'm running following code, observable fires once, not 20 times, anticipated.
it('does interval thing synchonously', ()=> { let x = []; let scheduler = new rx.testscheduler(); let interval$ = rx.observable.interval(500, scheduler).take(20); interval$.subscribe( value => { x.push(value); console.log(value) }, ); for(let = 0; < 20; i++) { scheduler.flush(); } expect(x.length).tobe(20); });
how make testscheduler
move observable forward 10000 milliseconds?
my understanding testscheduler
intended used marble testing , works observables composed returned createcoldobservable
, createhotobservable
methods.
instead, use virtualtimescheduler
- upon testscheduler
based:
let scheduler = new rx.virtualtimescheduler(); let interval$ = rx.observable.interval(500, scheduler).take(20); let values = []; interval$.subscribe(value => values.push(value)); scheduler.flush(); console.log(values);
.as-console-wrapper { max-height: 100% !important; top: 0; }
<script src="https://unpkg.com/rxjs/bundles/rx.min.js"></script>
note single flush
call required.
Comments
Post a Comment