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.

  1. export function fetchUserEpic(action$) {
  2. return action$.ofType('FETCH_USER')
  3. .map(action => ({
  4. type: 'FETCH_USER_FULFILLED',
  5. payload: {
  6. name: 'Shane',
  7. user: action.payload
  8. }
  9. }))
  10. }
  1. import {Observable} from 'rxjs';
  2. import {ActionsObservable} from 'redux-observable';
  3. import {fetchUserEpic} from "./fetch-user-epic";
  4. it('should return correct actions', function () {
  5. const action$ = ActionsObservable.of({
  6. type: 'FETCH_USER',
  7. payload: 'shakyshane'
  8. });
  9.  
  10. const output$ = fetchUserEpic(action$);
  11. output$.toArray().subscribe(actions => {
  12. expect(actions.length).toBe();
  13. });
  14. });

[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. 前端之CSS属性相关

    宽和高 width属性可以为元素设置宽度. height属性可以为元素设置高度. 块级标签才能设置宽度,内联标签的宽度由内容来决定. 字体属性 文字字体 font-family可以把多个字体名称作为一 ...

  2. 用xstart远程连接linux图形用户界面时发生已经在使用的情况

    1.举例打开pycharm 2.此时要输入ps aux|grep pycharm,出现下面的情况 3.然后找到矩形圈住的内容,然后输入 这样就杀掉了远程机子上pycharm,接着继续输入pycharm ...

  3. win7 ssd评分降为5.9的诡异问题解决方法

    某一天偶然发现win7的系统评分里面,磁盘一项由之前的7.9降到5.9了,SSD早听说会有降速的问题,但无论如何降,也不至于被降到5.9分这一机械硬盘普遍的分数. 百度搜了,Google搜了,中文搜了 ...

  4. Android组件Activity初探

    1.Activity是什么 Activity是Android系统中的四大组件之一,在MVC模式中属于C控制层 M(Model 模型):Model是应用程序的主体对象.       V(View 视图) ...

  5. ArcGIS api for javascript——设置自定义范围和空间参考

    描述 这个示例展示了在创建地图时如果定义一个自定义的范围和空间参考. 在 ArcGIS JavaScript API的1.0和1.1版本,任何要使用的地图服务图层都需要和地图的空间参考一致.1.2版本 ...

  6. typedef 与 set_new_handler的几种写法

    可以用Command模式.函数对象来代替函数指针,获得以下的好处: 1. 可以封装数据 2. 可以通过虚拟成员获得函数的多态性 3. 可以处理类层次结果,将Command与Prototype模式相结合 ...

  7. VGA接口时序约束

    SF-VGA模块板载VGA显示器DA转换驱动芯片AVD7123,FPGA通过OUPLLN连接器驱动ADV7123芯片产生供给VGA显示器的色彩以及同步信号.SF-CY3核心模块与SF-VGA子模块连接 ...

  8. css如何实现垂直居中(5种方法)

    css如何实现垂直居中(5种方法) 一.总结 一句话总结:行内只需要简单地把 line-height 设置为那个对象的 height 值就可以使文本居中了. 块的话可以尝试 margin:auto: ...

  9. vSphere5安装配置视频教程

    vSphere5安装配置视频教程 本文出自 "李晨光原创技术博客" 博客,请务必保留此出处http://chenguang.blog.51cto.com/350944/819550

  10. ipad 基础

    一.必备技巧 1.死机重启苹果的东西都比较稳定,但这并不等于iPad不会死机.死机了怎么办?iPad电池可是内置的,后盖一般用户也打不开.方法是:按住机身顶端的电源键和圆形的HOME键几秒钟,这时iP ...