Rxjs testing - is it possible to use marble diagrams also in RxJs 4?

空扰寡人 提交于 2019-12-12 02:59:35

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!