1

Using RXJS's TestScheduler, is there a nice way to marble-test an event-like observable that emits undefined values?

I am using TypeScript, so type circumvention / monkey-patching is not desirable.

testScheduler.schedule(() => valueEmittingWork(), 20);
testScheduler.schedule(() => valueEmittingWork(), 40);

testScheduler.run(rx => {
    rx.expectObservable(myObservable).toBe(`20ms ??? 19ms ???`);
    // Above uses the new time progression syntax. What do I put instead of ???
});
wh1t3cat1k
  • 3,146
  • 6
  • 32
  • 38

2 Answers2

0

As a workaround, I piped the source observable with .mapTo('a') and then was able to write:

testScheduler.run(rx => {
    rx.expectObservable(myObservable.pipe(mapTo('a'))).toBe(`20ms a 19ms a`);
});
wh1t3cat1k
  • 3,146
  • 6
  • 32
  • 38
0

You can test a void observable by setting a to undefined:

testScheduler.run(rx => {
    rx.expectObservable(myObservable).toBe('20ms a 10ms a', { a: undefined });
});
Nate Bundy
  • 513
  • 1
  • 5
  • 10