Book Image

Redux Quick Start Guide

By : James Lee, Tao Wei, Suresh Kumar Mukhiya
Book Image

Redux Quick Start Guide

By: James Lee, Tao Wei, Suresh Kumar Mukhiya

Overview of this book

Starting with a detailed overview of Redux, we will follow the test-driven development (TDD) approach to develop single-page applications. We will set up JEST for testing and use JEST to test React, Redux, Redux-Sage, Reducers, and other components. We will then add important middleware and set up immutableJS in our application. We will use common data structures such as Map, List, Set, and OrderedList from the immutableJS framework. We will then add user interfaces using ReactJS, Redux-Form, and Ant Design. We will explore the use of react-router-dom and its functions. We will create a list of routes that we will need in order to create our application, and explore routing on the server site and create the required routes for our application. We will then debug our application and integrate Redux Dev tools. We will then set up our API server and create the API required for our application. We will dive into a modern approach to structuring our server site components in terms of Model, Controller, Helper functions, and utilities functions. We will explore the use of NodeJS with Express to build the REST API components. Finally, we will venture into the possibilities of extending the application for further research, including deployment and optimization.
Table of Contents (16 chapters)
Title Page
Copyright and Credits
About Packt

Testing Redux

Let's add Redux to our project, in order to test it. You already know how to add JavaScript dependencies as follows:

yarn add react-redux--exact

Testing action creators

Action creators are pretty easy to test. We already explored what action creators are and how to use them in Chapter 1, Understanding Redux. As a reminder, in Redux, action creators are simply functions that return plain objects. Nothing complicated, right? Let's consider an action creator from our health application. We just made a function called addNewDoctor that takes new doctor data and returns the plain object, as follows:

export function addNewDoctor(newDoctorData) {
 return {
   type: "ADD_NEW_DOCTOR",

Let's test our action creators, as follows:

import * as actions from "../actionCreators";
describe("actions", () => {
 it("should create an action to add a doctor", () => {
   const newDoctorData = {
     name: "Dr. Yoshmi Mukhiya",
    email: "[email protected]",
     age: 22