How do I marble-test an observable of void values?

671 views Asked by At

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 ???
});
3

There are 3 answers

0
wh1t3cat1k On

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`);
});
1
AudioBubble On

This worked for me:

const source$ = hot<void>('a--')

0
Nate Bundy On

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

testScheduler.run(rx => {
    rx.expectObservable(myObservable).toBe('20ms a 10ms a', { a: undefined });
});