zoukankan      html  css  js  c++  java
  • [React Testing] The Redux Store

    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);
        });
    });
  • 相关阅读:
    网络攻击技术:SQL Injection(sql注入)
    人生若只如初见,何事秋风悲画扇
    TCPClient、TCPListener的用法
    C#中时间的Ticks属性
    string.Empty、" "、null 三者之间的区别
    telnet的使用解析
    public DataTable ExecuteQuery(string sql) 这段话具体意思
    C#中三层架构UI、BLL、DAL、Model详解(送给自学的初学者)
    数据库三层架构
    获取SQL Server数据库的表结构的做法
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5121857.html
Copyright © 2011-2022 走看看