Epics can be unit-tested just like any other function in your application - they have a very specific set of inputs (the action$ stream) and the output is always an Observable. We can subscribe to this output Observable to assert that the actions going back into the Redux are the ones we expect.

export function fetchUserEpic(action$) {
return action$.ofType('FETCH_USER')
.map(action => ({
type: 'FETCH_USER_FULFILLED',
payload: {
name: 'Shane',
user: action.payload
}
}))
}
import {Observable} from 'rxjs';
import {ActionsObservable} from 'redux-observable';
import {fetchUserEpic} from "./fetch-user-epic";
it('should return correct actions', function () {
const action$ = ActionsObservable.of({
type: 'FETCH_USER',
payload: 'shakyshane'
}); const output$ = fetchUserEpic(action$);
output$.toArray().subscribe(actions => {
expect(actions.length).toBe();
});
});

[Redux-Observable && Unit testing] Testing the output of epics的更多相关文章

  1. [Angular & Unit Testing] Testing a RouterOutlet component

    The way to test router componet needs a little bit setup, first we need to create a "router-stu ...

  2. [Angular] Testing @Input and @Output bindings

    Component: import { Component, Input, ChangeDetectionStrategy, EventEmitter, Output } from '@angular ...

  3. [Angular Unit Testing] Testing Component methods

    import {ComponentFixture, TestBed} from '@angular/core/testing'; import {BrowserDynamicTestingModule ...

  4. [Angular Unit Testing] Testing Services with dependencies

    import { Http, Response, ResponseOptions } from '@angular/http'; import { TestBed } from '@angular/c ...

  5. Run Unit API Testing Which Was Distributed To Multiple Test Agents

    Recently I am blocked by a very weird issue, from the VS installed machine, I can run performance te ...

  6. [AngularJS Unit tesint] Testing keyboard event

    HTML: <div ng-focus="vm.onFocus(month)", aria-focus="{{vm.focus == month}}", ...

  7. [Angular & Unit Testing] Testing Component with Store

    When using Ngrx, we need to know how to test the component which has Router injected. Component: imp ...

  8. [AngularJS + Unit Testing] Testing Directive's controller with bindToController, controllerAs and isolate scope

    <div> <h2>{{vm.userInfo.number}} - {{vm.userInfo.name}}</h2> </div> 'use str ...

  9. [AngularJS + Unit Testing] Testing a component with requiring ngModel

    The component test: describe('The component test', () => { let component, $componentController, $ ...

随机推荐

  1. BZOJ 2724 [Violet 6]蒲公英(分块)

    题意 在线区间众数 思路 预处理出 f[i][j] 即从第 i 块到第 j 块的答案.对于每个询问,中间的整块直接用预处理出的,两端的 sqrtn 级别的数暴力做,用二分查找它们出现的次数.每次询问的 ...

  2. 紫书 习题 10-3 UVa 1643(计算几何 叉乘)

    直观感觉对角线重合的时候面积最大 然后可以根据方程和割补算出阴影部分的面积 注意知道两点坐标,可以求出与原点形成的三角形的面积 用叉乘,叉乘的几何意义以这两个向量为边的平行四边形的面积 所以用叉乘除以 ...

  3. HTML学习----------DAY1 第二节

    使用 Notepad 或 TextEdit 来编写 HTML 可以使用专业的 HTML 编辑器来编辑 HTML: Adobe Dreamweaver Microsoft Expression Web ...

  4. jQuery模拟输出回车键

    jQuery模拟输出回车键 学习了:https://zhidao.baidu.com/question/1753748968579760068.html 原文少了个r var e = jQuery.E ...

  5. [问题]HDOJ1032 The 3n + 1 problem

    http://acm.hdu.edu.cn/showproblem.php? pid=1032 这题能够用暴力求解.求出在[ni,nj]之间全部数字产生的最大值. 通过观察能够知道,当nk靠近nj的时 ...

  6. hdu 3068 最长回文 【Manacher求最长回文子串,模板题】

    欢迎关注__Xiong的博客: http://blog.csdn.net/acmore_xiong?viewmode=list 最长回文                                 ...

  7. HDU4565 So Easy! 矩阵高速幂外加数学

    easy 个屁啊,一点都不easy,题目就是要求公式的值,但是要求公式在最后的取模前的值向上取整.再取模,无脑的先试了高速幂 double  fmod来做,结果发现是有问题的.这题要做肯定得凑整数,凑 ...

  8. Codeforces Round #316 (Div. 2) B. Simple Game

    思路:把n分成[1,n/2],[n/2+1,n],假设m在左区间.a=m+1,假设m在右区间,a=m-1.可是我居然忘了处理1,1这个特殊数据.被人hack了. 总结:下次一定要注意了,提交前一定要看 ...

  9. 如何下载最新版的 Adobe Flash Player

    如何下载最新版的 Adobe Flash Player 中国访客用代理访问下面的链接,否则会自动跳转到 https://www.flash.cn/ 当我们从 https://get.adobe.com ...

  10. Codefroces B. T-primes

    http://codeforces.com/problemset/problem/230/B B. T-primes time limit per test 2 seconds memory limi ...