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. html图像入门

    在HTML中,图像由<img>标签定义. <img>是空标签,意思是说,它只包含属性,并且没有闭合标签. 要在页面上显示图像,需要使用源属性src, src指的是"s ...

  2. GridView and DropDownList

    <form id="form1" runat="server"> <div> <asp:GridView runat=" ...

  3. jquery ajax 跨域处理

    今天使用JQuery Ajax 在本地电脑获取远程服务器数据的时候,发现使用$.ajax,$.getJSON,$.get这些都没有反应,后来再统一个网站下测试了一下,代码写得没有问题.后来想了想好想, ...

  4. Installing node-oracledb on Microsoft Windows

    版本 7 由 Laura Ramsey-Oracle 于 2015-10-19 下午11:46创建,最后由 cj 于 2015-10-22 下午7:44修改. Installing node-orac ...

  5. swing常用布局

    1,FlowLayout 窗口的默认布局 设置窗口布局方法(下面不重复 setLayout(new FlowLayout()); 设置容器布局方法 比如容器 con1 con1.setLayout(n ...

  6. 外国高手画神级的linux 内核图,够详细!

  7. ValidateCode.cs验证码时设置缓存的使用

    using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System. ...

  8. JQUERY1.9学习笔记 之基本过滤器(五) 大于选择器

    大于选择器:jQuery( ":gt(index)" )jQuery( ":gt(-index)" ) 例:大于TD5 到TD8 用黄色背景,TD8用红色文字. ...

  9. PHP获取操作系统、IP、地理位置、浏览器、ISP等信息_PHP类代码

    PHP语言.浏览器.操作系统.IP.地理位置.ISP,本PHP类里面有以下几种方法,同时也是用法说明: <?php class class_guest_info{ function GetLan ...

  10. twsited(4)--不同模块用redis共享以及用web发送数据到tcpserver

    上一章开头我们说,要连接之前flask系列文章中的用户,结果篇幅不够,没有实现. 今天我们把它实现一下.话说,不同模块之间,该如何联系在一起,通常都是mysql.redis.rabbitmq还有RPC ...