[React Testing] The Redux Store - Multiple Actions
When using Redux, we can test that our application state changes are working by testing that dispatching actions to the store creates our expected output. In this lesson we will run a few realistic actions back to back (as if the user is using the app) and then test that the state tree looks as we expect it to. These types of tests that ensure all of your redux logic is working as expected give you a lot of value for not too much effort (they test your entire app's state in one big swoop). You may also find it useful to add more granular/individual tests for your reducers and/or actions, which we will cover in other lessons in this course.
import expect from 'expect';
import {store} from './store'; describe('store', () => { it('should initialize', () => {
const actual = store.getState();
const expected = {
quotes: [],
theme: {
color: '#5DC4C6'
}
};
expect(actual).toEqual(expected);
}); it('should work with a series of actions', () => { const actions = [
{
type: 'ADD_QUOTE_BY_ID',
payload: {
text: 'The best way to cheer yourself up is to try to cheer somebody else up.',
author: 'Mark Twain',
id: 1,
likeCount: 24
}
},
{
type: 'ADD_QUOTE_BY_ID',
payload: {
text: 'Whatever you are, be a good one.',
author: 'Abraham Lincoln',
id: 2,
likeCount: 0
}
},
{
type: 'REMOVE_QUOTE_BY_ID',
payload: {id: 1}
},
{
type: 'LIKE_QUOTE_BY_ID',
payload: {id: 2}
},
{
type: 'LIKE_QUOTE_BY_ID',
payload: {id: 2}
},
{
type: 'UNLIKE_QUOTE_BY_ID',
payload: {id: 2}
},
{
type: 'UPDATE_THEME_COLOR',
payload: {color: '#777777'}
}
]; actions.forEach(action => store.dispatch(action)); const actual = store.getState();
const expected = {
quotes: [
{
text: 'Whatever you are, be a good one.',
author: 'Abraham Lincoln',
id: 2,
likeCount: 1
}
],
theme: {
color: '#777777'
}
}; expect(actual).toEqual(expected);
});
});
[React Testing] The Redux Store - Multiple Actions的更多相关文章
- [React + Functional Programming ADT] Create Redux Middleware to Dispatch Multiple Actions
We only have a few dispatching functions that need to be known by our React Application. Each one ac ...
- [Redux-Observable && Unit Testing] Use tests to verify updates to the Redux store (rxjs scheduler)
In certain situations, you care more about the final state of the redux store than you do about the ...
- 在React中使用Redux
这是Webpack+React系列配置过程记录的第六篇.其他内容请参考: 第一篇:使用webpack.babel.react.antdesign配置单页面应用开发环境 第二篇:使用react-rout ...
- React 环境增加Redux ,React-Redux
引入 Redux 的目的, 状态管理! React-Redux 就是完成一些粘合剂的作用. 简而化之的理解就是将数据放在store 中维护, 操作逻辑放在reducer中去写. 更功利的表达就是: ...
- 在react中使用redux并实现计数器案例
React + Redux 在recat中不使用redux 时遇到的问题 在react中组件通信的数据是单向的,顶层组件可以通过props属性向下层组件传递数据,而下层组件不能向上层组件传递数据,要实 ...
- React,关于redux的一点小见解
最近项目做多页面应用使用到了,react + webpack + redux + antd去构建多页面的应用,本地开发用express去模拟服务端程序(个人觉得可以换成dva).所以在这里吐槽一下我自 ...
- react系列(五)在React中使用Redux
上一篇展示了Redux的基本使用,可以看到Redux非常简单易用,不限于React,也可以在Angular.Vue等框架中使用,只要需要Redux的设计思想的地方,就可以使用它. 这篇主要讲解在Rea ...
- [Functional Programming ADT] Create a Redux Store for Use with a State ADT Based Reducer
With a well defined demarcation point between Redux and our State ADT based model, hooking up to a R ...
- [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 ...
随机推荐
- sql 判断表、列、视图等是否存在
1 判断数据库是否存在 if exists (select * from sys.databases where name = '数据库名') drop database [数据库名] 2 判 ...
- GridView、Repeater获取当前行号
GridView: <%# Container.DataItemIndex+1 %> Repeater:<%# Container.ItemIndex+1%>
- Android开发手记(7) 按钮类控件的使用
1.点击Button改变页面背景色 通过Button改变页面背景色,首先新建相应的对象,让后绑定到Layout上的元素. final RelativeLayout layout = (Relative ...
- C++拾遗(七)函数相关(2)
内联函数 内联函数与常规函数的区别在于: 1.常规函数:在执行调用指令时,先存储该指令的内存地址,将函数参数复制到堆栈,然后跳转到被调用函数起点的内存单元,执行函数,将返回值放 入寄存器,最后跳回到一 ...
- pyenv简介——Debian/Ubuntu中管理多版本Python
pyenv简介——Debian/Ubuntu中管理多版本Python MAY 21ST, 2016 12:00 AM | COMMENTS pyenv是管理Python版本的工具,它支持在多个Pyth ...
- 怎么加sudo权限
安装好Debian后还不能使用sudo如果没有安装sudo,则在root用户下apt-get install sudo在root设置sudoers配制文件chmod +w /etc/sudoersvi ...
- java-map-IdentityHashMap
1.背景 今天翻开IdentityHashMap的时候,就傻眼了,这个到底是个逻辑啊,我的程序代码如下: IdentityHashMap<String,String> identityHa ...
- Verilog HDL中阻塞语句和非阻塞语句的区别
在Verilog中有两种类型的赋值语句:阻塞赋值语句(“=”)和非阻塞赋值语句(“<=”).正确地使用这两种赋值语句对于Verilog的设计和仿真非常重要. Verilog语言中讲的阻塞赋值与非 ...
- Entity Framework with MySQL 学习笔记一(insert,update,delete)
先说说 insert 吧. 当EF执行insert时,如果我们传入的对象是有关联(1对多等)的话,它会执行多个语句 insert到多个表, 并且再select出来填充我们的属性(因为有些column默 ...
- [LeetCode 112 113] - 路径和I & II (Path Sum I & II)
问题 给出一棵二叉树及一个和值,检查该树是否存在一条根到叶子的路径,该路径经过的所有节点值的和等于给出的和值. 例如, 给出以下二叉树及和值22: 5 / \ 4 8 ...