Rxjs 测试 - 是否也可以在 RxJs 4 中使用大理石图? [英] Rxjs testing - is it possible to use marble diagrams also in RxJs 4?

查看:46
本文介绍了Rxjs 测试 - 是否也可以在 RxJs 4 中使用大理石图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的问题.RxJS v5 使用大理石图进行测试(示例此处).是否可以在 RxJS v4 中使用相同的技术?如果可以,如何使用?

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 ?

推荐答案

你总是可以推出你自己的:这里有一个简单的函数可以将字符串转换为一个冷 observable 并发出字符串值:

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

这篇关于Rxjs 测试 - 是否也可以在 RxJs 4 中使用大理石图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆