问题
I have a simple question. RxJS v5 uses marble diagrams for its testing (example here). Is it possible to use the same technique in RxJS v4 and if so, how to ?
回答1:
You can always roll your own: here's a simple function to convert a string to a cold observable that emits string values:
// string -> Observable<string>
function fromMarble(s) {
const items = s.split('-')
.filter(x => x);
return Rx.Observable.from(items);
}
fromMarble('--1--2--cheese--4--5').subscribe(x => console.log(x));
// >> 1
// >> 2
// >> cheese
// >> 4
// >> 5
来源:https://stackoverflow.com/questions/35762776/rxjs-testing-is-it-possible-to-use-marble-diagrams-also-in-rxjs-4