Install:

npm install — save-dev jasmine-marbles

Basic example:

import {cold, getTestScheduler} from 'jasmine-marbles';
import 'rxjs/add/operator/concat'; describe('Test', () => {
it('concat', () => {
const one$ = cold('x-x|');
const two$ = cold('-y|'); expect(one$.concat(two$)).toBeObservable(cold('x-x-y|'));
});
});

Advanced example:

import { MovieShowingsComponent } from './movie-showings.component';
import { cold, getTestScheduler } from 'jasmine-marbles'; describe('MovieShowingsComponent', () => {
it('should not have a race condition', () => {
const backend = jasmine.createSpyObj('backend', ['getShowings']);
const cmp = new MovieShowingsComponent(backend); backend.getShowings.and.returnValue(cold('--x|', {x: ['10am']}));
cmp.selectMovie('After the Storm'); backend.getShowings.and.returnValue(cold('-y|', {y: ['11am']}));
cmp.selectMovie('Paterson'); // this will flush all observables
getTestScheduler().flush(); expect(cmp.movieTitle).toEqual('Paterson');
expect(cmp.showings).toEqual(['11am']); // This will fail because showings is ['10am'].
});
});

Component:

@Component({
selector: 'movie-showings-cmp',
templateUrl: './movie-showings.component.html'
})
export class MovieShowingsComponent {
public movieTitle: string;
public showings: string[]; private getShowings = new Subject<string>(); constructor(private backend: Backend) {
this.getShowings.switchMap(movieTitle => this.backend.getShowings(movieTitle)).subscribe(showings => {
this.showings = showings;
});
} showShowings(movieTitle: string) {
this.movieTitle = movieTitle;
this.getShowings.next(movieTitle);
}
}

[RxJS] Marbles Testings的更多相关文章

  1. [RxJS] Introduction to RxJS Marble Testing

    Marble testing is an expressive way to test observables by utilizing marble diagrams. This lesson wi ...

  2. 构建流式应用—RxJS详解[转]

    目录 常规方式实现搜索功能 RxJS · 流 Stream RxJS 实现原理简析 观察者模式 迭代器模式 RxJS 的观察者 + 迭代器模式 RxJS 基础实现 Observable Observe ...

  3. RxJS库

    介绍 RxJS是一个异步编程的库,同时它通过observable序列来实现基于事件的编程.它提供了一个核心的类型:Observable,几个辅助类型(Observer,Schedulers,Subje ...

  4. RxJS + Redux + React = Amazing!(译一)

    今天,我将Youtube上的<RxJS + Redux + React = Amazing!>翻译(+机译)了下来,以供国内的同学学习,英文听力好的同学可以直接看原版视频: https:/ ...

  5. RxJS + Redux + React = Amazing!(译二)

    今天,我将Youtube上的<RxJS + Redux + React = Amazing!>的后半部分翻译(+机译)了下来,以供国内的同学学习,英文听力好的同学可以直接看原版视频: ht ...

  6. [译]RxJS 5.X基础篇

    欢迎指错与讨论 : ) 当前RxJS版本:5.0.0-beta.10.更详细的内容尽在RxJS官网http://reactivex.io/rxjs/manual/overview.html.文章比较长 ...

  7. 学习RxJS: 导入

    原文地址:http://www.moye.me/2016/05/31/learning_rxjs_part_one_preliminary/ 引子 新手们在异步编程里跌倒时,永远会有这么一个经典问题: ...

  8. Marbles启动信息

    body-parser deprecated undefined extended: provide extended option app.js:40:20 -------------------- ...

  9. UVA 10090 - Marbles 拓展欧几里得

    I have some (say, n) marbles (small glass balls) and I am going to buy some boxes to store them. The ...

随机推荐

  1. CF983E NN country(倍增,差分)

    题意 给定一棵树和若干条路线,每条路线相当于树上 x,y 之间的路径,途径路径上的每个点 给出若干个询问,每次询问从 u 到 v 至少需要利用几条路线 N,M,Q≤200000 题解 构建倍增数组g[ ...

  2. [洛谷P1726][codevs1332]上白泽慧音

    题目大意:求一个有向图的最大强连通分量中点的个数,并输出这些点(字典序最小). 解题思路:裸的强连通分量. 数据小,求完强连通分量后排序+vector大小比较即可(vector有小于运算符). C++ ...

  3. Win10+TensorFlow-gpu pip方式安装,anaconda方式安装

    中文官网安装教程:https://www.tensorflow.org/install/install_windows#determine_how_to_install_tensorflow 1.安装 ...

  4. HDU——T 2818 Building Block

    http://acm.hdu.edu.cn/showproblem.php?pid=2818 Time Limit: 2000/1000 MS (Java/Others)    Memory Limi ...

  5. COGS——T1588. [USACO FEB04]距离咨询

    http://cogs.pro/cogs/problem/problem.php?pid=1588 ★★   输入文件:dquery.in   输出文件:dquery.out   简单对比时间限制:1 ...

  6. android 2048游戏实现

    android 的2048小游戏完整实现:GridLayout布局(android 4.0及以上). 曾经做过一个2048的算法题,学了几天android,认为能够实现个安卓版的.也就动手写了个. 包 ...

  7. Thrift 基础教程(一)安装篇

    1.Thrift简单介绍 Thrift是一款由Fackbook开发的可伸缩.跨语言的服务开发框架,该框架已经开源而且增加的Apache项目.Thrift主要功能是:通过自己定义的Interface D ...

  8. Windows cannot find ". Make sure you typed the name correctly, and then try again

    https://answers.microsoft.com/en-us/windows/forum/windows_10-desktop/windows-10-explorerexe-error-wi ...

  9. 温习 socket http tcp

    Socket是一个接口,可以实现TCP或者UDP的传输HTTP是协议 资料: 1.TCP/IP连接 手机能够使用联网功能是因为手机底层实现了TCP/IP协议,可以使手机终端通过无线网络建立TCP连接. ...

  10. react-native使用androidstudio时,安卓模拟器reload菜单界面显示快捷键ctrl+M;

    react-native使用androidstudio时,安卓模拟器reload菜单界面显示快捷键ctrl+M: