[Redux-Observable && Unit testing] Testing the output of epics
2024-08-31 17:06:38
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();
});
});
最新文章
- C#开发微信门户及应用(43)--微信各个项目模块的定义和相互关系
- Struts2 自定义MVC框架
- eclipse中一些设置&;配置项
- poj1416 Shredding Company
- 如何确定C#代码是在编译时执行还是在运行时执行
- 更加优雅地搭建SSH框架(使用java配置)
- 正确对待bug
- 转:ASP.NET MVC扩展之HtmlHelper辅助方法
- 【转】在企业内部分发 iOS 应用程序
- HDOJ(HDU) 4847 Wow! Such Doge!(doge字符统计)
- javascript中的动画的实现以及运动框架的编写(1)
- B树及B+树
- MyBaits集合的嵌套 Select 查询
- PSP耗时
- SharePoint 2016 - 安装QuickFlow2013
- C语言编程知识点
- express文件上传中间件Multer详解
- HTML5 Canvas水波纹动画特效
- hive中窗口分析函数
- bzoj3751 / P2312 解方程