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的更多相关文章

  1. [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 ...

  2. [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 ...

  3. 在React中使用Redux

    这是Webpack+React系列配置过程记录的第六篇.其他内容请参考: 第一篇:使用webpack.babel.react.antdesign配置单页面应用开发环境 第二篇:使用react-rout ...

  4. React 环境增加Redux ,React-Redux

    引入 Redux 的目的, 状态管理! React-Redux 就是完成一些粘合剂的作用. 简而化之的理解就是将数据放在store 中维护, 操作逻辑放在reducer中去写. 更功利的表达就是:  ...

  5. 在react中使用redux并实现计数器案例

    React + Redux 在recat中不使用redux 时遇到的问题 在react中组件通信的数据是单向的,顶层组件可以通过props属性向下层组件传递数据,而下层组件不能向上层组件传递数据,要实 ...

  6. React,关于redux的一点小见解

    最近项目做多页面应用使用到了,react + webpack + redux + antd去构建多页面的应用,本地开发用express去模拟服务端程序(个人觉得可以换成dva).所以在这里吐槽一下我自 ...

  7. react系列(五)在React中使用Redux

    上一篇展示了Redux的基本使用,可以看到Redux非常简单易用,不限于React,也可以在Angular.Vue等框架中使用,只要需要Redux的设计思想的地方,就可以使用它. 这篇主要讲解在Rea ...

  8. [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 ...

  9. [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 ...

随机推荐

  1. W3C小组宣布:HTML5标准制定完成

    近日,W3C小组宣布已经完成对HTML5标准以及Canvas 2D性能草案的制定,这就意味着开发人员将会有一个稳定的“计划和实施”目标. Web性能工作组已经推出W3C的两个版本建议草案. Navig ...

  2. Cacti监控Windows主机,Windows主机的正确配置

    使用cacti监控Windows主机的时候经常遇到无法获取Windows主机的snmp信息和Windows主机的硬件信息,主要原因是Windows主机没有正确配置snmp,以下是正确的配置步骤:1.安 ...

  3. foreach遍历原理(一)

    前言 要使用foreach的遍历的类首先要满足的条件 1. 类要实现公共方法 public IEnumerator GetEnumerator(){},还可以继承IEnumerable接口来实现这个方 ...

  4. php 设置报错等级

    定义和用法:    error_reporting() 设置 PHP 的报错级别并返回当前级别. 函数语法:    error_reporting(report_level) 如果参数 level 未 ...

  5. CSS块级元素与行级元素(转载)

    块元素一般都从新行开始,它可以容纳内联元素和其他块元素,常见块元素是段落标签'P".“form"这个块元素比较特殊,它只能用来容纳其他块元素. 如果没有css的作用,块元素会顺序以 ...

  6. C++:MEMSET的大坑三两事

    之前写了一题费用流,竟然硬是在写SPFA时为DIS数组赋初始值用了MEMSET数组QAQ 调试了很久也没有弄明白自己是卡在那里了,,,感觉被自己蠢哭了QWQ 错误的姿势!! #include < ...

  7. github 使用方法总结 还有一部分不太懂

    1  github在新的目录下添加新的文件 git init //在相应的目录下添加 git add //添加目录 git commit -m "first commit" git ...

  8. Array and its point.

    a is the array name. &a is the ponit of 2-D array which contains a[5]. the type of &a should ...

  9. Linux_service cloudera-scm-server start failed

    see log : /var/log/cloudera-scm-server/cloudera-scm-server.log

  10. iOS摄像头和相册-UIImagePickerController-浅析(转)

    iOS摄像头和相册-UIImagePickerController-浅析(转) 转自: http://blog.sina.com.cn/s/blog_7b9d64af0101cfd9.html 在一些 ...